String correlation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

String correlation

Post by zenon »

Hello.

When a user writes a string, for example "spagetti" or "spag" or "spaget" or something like that, i want to recognize the string and put on its place other string, like "pasta" and use the latest string in a query in a database.

I hope i didn't confuse you.

Thank you!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: String correlation

Post by jackpf »

I may be mistaken, but I don't believe that's possible...

You'd have to make a table or something of correlation. Say, have a field for word match, and then for match value.
Then you can use LIKE with wild cards in the query, to select words that have a correlation, and use that word in the new query instead.


For example:

the table:

Code: Select all

 
| Word Match| Word Value |
|                  |                   |
| spaghetti   | pasta          |
 
Say the word is "spag", do:

Code: Select all

SELECT `Word Value` FROM TABLE WHERE `Word Match` LIKE '%spag%'
Then `Word Value` should contain "pasta". If you were to get a bit more advanced, I guess you could have a ranking system, so that if multiple matches are found, you can decide which one is most like what the user meant in context.
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

Re: String correlation

Post by zenon »

Thank you very much jackpf for your helpful advice!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: String correlation

Post by jackpf »

Sorry, I edited my post to give an example. I wasn't sure if you saw it...I just thought I'd let you know.

Anyway, yeah, no problem. Good luck!
zenon
Forum Commoner
Posts: 42
Joined: Fri Jan 23, 2009 1:41 pm

Re: String correlation

Post by zenon »

jackpf wrote:Sorry, I edited my post to give an example. I wasn't sure if you saw it...I just thought I'd let you know.

Anyway, yeah, no problem. Good luck!
Yes, i saw it :D

Thank very much once again! I appreciate it!
Post Reply