Jump to content

text form exploded into individual words help


paulmo

Recommended Posts

I've got several "if/elseif" arrays that follow the code below, where message ($word) comes from submitted text form that contains sentences with ANY words. problem is, only the LAST word in message is being searched against my if/elseif arrays. I need EVERY word from message searched.  so my $word variable isn't right.

 

my //comments are here to show different things I've played with.

 

$message = $_POST['message'];

$post_message = ucfirst($message);
$message = mysql_real_escape_string($message); 
$message = strip_tags($message); 
//$message = trim ($message); 
$pre_filter=trim($message);

$get_search=explode(" ",$pre_filter);
//$post_message = stripslashes($post_message);

//$where = '';

foreach ($get_search as $word)
{
$word = trim($word);
// $skip = false; use this later 
}

I've tried with and without pre_filter(trim).  Still, only last word of string is being searched, whereas I need EVERY word searched. Thanks again in advance.

$message = strip_tags($message); 
$message = mysql_real_escape_string($message); 
//$pre_filter=trim($message);

$wordchunks = explode(" ", $message);
for($i = 0; $i < count($wordchunks); $i++){
echo "Word: $i = $wordchunks[$i] <br />";
}
//$message = preg_split("/[\s,]+/")($message);
foreach ($wordchunks as $word)
{
$word = trim($word);
$skip = false;
}

thanks for the suggestion; please help fine tune. still not working. i'm sure i'm supposed to do something with new $where variable--just don't know what.

$wordchunks = explode(" ", $message);
$where = "(message LIKE '%" . implode("%' OR message LIKE '%", $wordchunks) . "%')";
for($i = 0; $i < count($wordchunks); $i++){
echo "Word: $i = $wordchunks[$i] <br />";
}
//$message = preg_split("/[\s,]+/")($message);
foreach ($wordchunks as $word)
{
$word = trim($word);
$skip = false;
}

 

if arrays follow...

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.