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;
}
}
精彩评论