Random dictionary word for given letter

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
sathishkumar
Forum Newbie
Posts: 7
Joined: Mon Mar 15, 2010 11:43 pm

Random dictionary word for given letter

Post by sathishkumar »

hi everybody

Is there any possible code for getting output in php(all possible word from word dictionary)

for example....for word "werflo"

flower

fowler

reflow

wolfer
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Random dictionary word for given letter

Post by John Cartwright »

I think your best bet would be to mutate your string into every possible combination, then perform a look up in a dictionary database to determine which words exist in the given language.

pspell_check() may also be of interest to determining whether the spelling is correct or invalid (assuming you have the pspell extension).
sathishkumar
Forum Newbie
Posts: 7
Joined: Mon Mar 15, 2010 11:43 pm

Re: Random dictionary word for given letter

Post by sathishkumar »

Hi john,

Thanks your quick can you guide me with piece of code for this if possible. because i tired but many in vains.


Regards,
sathish
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Random dictionary word for given letter

Post by John Cartwright »

What have you tried? ..and what specifically are you having trouble with? I generally won't write anything beyond simple code for anyone without them demonstrating a little effort first.
sathishkumar
Forum Newbie
Posts: 7
Joined: Mon Mar 15, 2010 11:43 pm

Re: Random dictionary word for given letter

Post by sathishkumar »

I tried to get different combination of letter with looping. and i compared it with word dictionary but it takes much time to processing.

i want extact like unscramble in http://www.unscramble.net.


Regards,
sathish
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Random dictionary word for given letter

Post by John Cartwright »

Also see http://cogo.wordpress.com/2008/01/08/st ... on-in-php/ to generate word permutations.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Random dictionary word for given letter

Post by John Cartwright »

sathishkumar wrote:I tried to get different combination of letter with looping. and i compared it with word dictionary but it takes much time to processing.

i want extact like unscramble in http://www.unscramble.net.


Regards,
sathish
Again.. I'm not here to write code for you. I'm here to help you learn..

Post what you have tried, and we can move forward from there.
sathishkumar
Forum Newbie
Posts: 7
Joined: Mon Mar 15, 2010 11:43 pm

Re: Random dictionary word for given letter

Post by sathishkumar »

John I found word permutation there is no problem in it. but when compare it with word dictionary inside my database. it takes much time john(looping to compare 4 lakh words). is there any binary search for this?


Regards,
sathish
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Random dictionary word for given letter

Post by John Cartwright »

Performing a query against all permutations should not take long at all assuming you have a properly indexed your table.

Code: Select all

$permutations = your_permutation_function('foobar'); //array of permutations
 
$sql = "
   SELECT * 
   FROM dictionary
   WHERE word IN ('". implode("','", $permutations) ."')
";
I have asked you twice already to post what you have tried so far. This is the last time I will post here until you can provide the code you have done. I am simply grasping at straws otherwise...

It would also be helpful to see your table structure.
Post Reply