paulmo Posted December 30, 2009 Share Posted December 30, 2009 the following exploded text string gets searched against several if arrays in application. only the LAST word of the text string is being matched, whereas I need ALL words searched. now, only "dogs" is being matched in the sentence "you like dogs." where I need "you" "like" and "dogs" ALL searched.I have left // comments; pre_filter-trim has no effect on outcome either way. thanks in advance $message = strip_tags($message); $message = mysql_real_escape_string($message); //$pre_filter=trim($message);//$message = preg_split("/[\s,]+/")($message);$wordchunks = explode(" ", $message);for($i = 0; $i < count($wordchunks); $i++){ echo "Word: $i = $wordchunks[$i] <br />";}foreach ($wordchunks as $word){$word = trim($word);$skip = false;} if arrays follow... Link to comment Share on other sites More sharing options...
jeffman Posted December 30, 2009 Share Posted December 30, 2009 Have you echoed $message before and after the strip and escape functions? Always good to know what the string looks like bfore you explode it. Link to comment Share on other sites More sharing options...
paulmo Posted December 30, 2009 Author Share Posted December 30, 2009 Have you echoed $message before and after the strip and escape functions? Always good to know what the string looks like bfore you explode it.yes and yes. any idea on the code? thanks Link to comment Share on other sites More sharing options...
jeffman Posted December 30, 2009 Share Posted December 30, 2009 The for-loop worked fine when I tested it. It's a pretty simple thing. No reason it shouldn't work. I'm curious to know why your original preg_split was more complicated. Do your strings actually contain other whitespace characters besides " " ?Have you done obvious things like clear your cache or append a ?query string to your url to make sure the script gets loaded fresh? Link to comment Share on other sites More sharing options...
paulmo Posted December 30, 2009 Author Share Posted December 30, 2009 thanks for testing. not sure on preg_split; must have picked it up somewhere and tested it. I do clear cache although unfamilar with append ?query. Perhaps other issue of elseif will shed light. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.