Here is what I am trying to accomplish, I am making a search feature through PHP and MySQL, I am using MYSQL REGEXP feature to search.
I need to make the regex search for fullwords aligned. Meaning...
Lets say there is a entry named "This is alot of fun"
These would match it:
This
This is
This is alot
is alot
of fun
These wouldnt match it
This alot (missing "is")
is fun (missing "alot of")
Here is my php code.
I left out the MySQL code because its not important.
Now there is a entry called "Just for (re) FUN (ding)"
In the search box I typed "just for"
$newSearch was "^(.*\s*)?just[\s]+for(\s*.*)?$"
I dont understand why it didnt match?? Please help!!
I need to make the regex search for fullwords aligned. Meaning...
Lets say there is a entry named "This is alot of fun"
These would match it:
This
This is
This is alot
is alot
of fun
These wouldnt match it
This alot (missing "is")
is fun (missing "alot of")
Here is my php code.
Code:
unset($newSearch);
$searchStr = preg_quote(rtrim(trim($_POST['search'])), '/');
$var = preg_split("/\s/", $searchStr);
$num = count($var);
$key=1;
foreach($var as $word)
{
if($key=='1')
{
$newSearch .= '^(.*\s*)?'.$word;
}
else
{
$newSearch .= $word;
}
if($key!=$num)
{
$newSearch .= '[\s]+';
}
$key++;
}
$newSearch .= '(\s*.*)?$';
I left out the MySQL code because its not important.
Now there is a entry called "Just for (re) FUN (ding)"
In the search box I typed "just for"
$newSearch was "^(.*\s*)?just[\s]+for(\s*.*)?$"
I dont understand why it didnt match?? Please help!!