Jump to content

Exploded Text Only Searching Last Word


paulmo

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...