0

I need to find substrings of a given string but the substrings must be a word in the English language.

I.E. Given string = every, then substrings will be "ever", "very" and etc.

Thanks for the help.

2
  • do u have a set of words you want to match with? like a hashtable of dictionary words? if you do you can just do preg_match the string with the array and output the matched words. Commented Mar 10, 2011 at 19:06
  • 2
    google.com/patents/about?id=RJ04AAAAEBAJ&dq=5,884,272 Commented Mar 10, 2011 at 19:09

1 Answer 1

2

You will need two things. First, you have to find all possible substrings. Then you will need a list with all English words (there are many free compilations).

This is a possible implementation:

$result = array();
$len = strlen($string)
for ($i = 0; $i < $len; $i++) {
   for ($j = 1; $j <= $len - $i; $j++) {
      $substring = substr( $string , $i , $j );

      if ( is_an_english_word( $substring ) )
         $result[] = $substring;

   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.