Jump to content

Exploded Text Only Searching Last Word


paulmo
 Share

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...

Edited by paulmo
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...