Jump to content

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 
}

the trim function is removing any spaces... then you're trying to explode it by any spaces, were you after ltrim() and rtrim()? that would remove the whitespace etc from the start and the end, then you can explode it after that.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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