php - Split strings into Dictionary words -
I am looking to see if a string is the most efficient algorithm for PHP only or not-was created from words to check Am
Example:
thissentencewasmadefromenglishwords thisonecontainsyxxxyxsomegarbagexaatoo net thisisalsobadxyyyaazzz Output:
thissentencewasmadefromenglishwords net a.txt
are dictionary words b.txt
wire: one character only
I recommend a recursive approach like this: & lt; Php $ wordsToCheck = array ('otherword', 'word1andother', 'word1k', 'word1word2', 'word1word3', 'word1word2word3'); $ WordList = array ('word1', 'word2', 'word3'); $ Result = array (); Function OnlyListed Words ($ word, $ word list) {if_array ($ word, $ wordList)} {return true; } And {$ length = Stellen ($ word); $ WordTemp = $ word; $ Part = ''; For ($ i = 0; $ i & lt; $ length; $ i ++) {$ part = $ WordTemp [$ i]; If (in_array ($ part, $ wordList)) {if ($ i == $ length - 1) {true back; } And {$ wordTemp = substr ($ wordTemp, $ i + 1); Return only the words ($ wordTemp, $ wordList); }}}}} Check as Foreach ($ word $ word) {if (only ListedWords ($ word, $ wordList)) $ results [] = $ word; } Var_dump ($ result); ? & Gt;
Comments
Post a Comment