开发者

PHP - Sub-string words of a string

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 e开发者_运维百科tc.

Thanks for the help.


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;

   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜