Friday, January 22, 2010

Word scramble/jumble solver [limited dictionary]

<?php

$wordArray = array(); //YOUR DICTIONARY
function sortWord($letters)
{
   $letterArray = str_split($letters);
   sort($letterArray);
   return implode('', $letterArray);
}
function findWord($letters, $wordArray)
{
   $word1 = sortWord($letters);
   foreach($wordArray as $word2)
   {
      if(strtolower($word1) == sortWord(strtolower($word2)))
      {
         return $word2;
      }
   }
   return "No Results";
}

//FEED FINDWORD YOUR SCRAMBLED LETTERS AND THE WORDS DICTIONARY
echo findWord($letters, $wordArray);
?>

So basically this is useful if you want to solve a word jumble based on a defined dictionary

No comments:

Post a Comment