The problem:
Let’s say I have $keyword = a sentence entered into a search box, such as “large white boxes”
What I need to do is break this into individual words, and then test each word to make sure a * doesn’t appear within the first 3 letters. (So, sen* would be ok, but se* would NOT be ok). If a * does appear in first 3 letters of any individual word, then the “if ($keyword) …” process needs to end.
if ($keyword) {
$token = strtok($keyword, " ");
while ($token != false) {
echo $token;
if (stripos($token,"*") < 3 ) {
return;
}
$token = strtok(" ");
}
…code continues…
As you can see, I am echoing each time to see it processing.
If I get rid of the ‘if’ code, then it outputs ‘largewhiteboxes’ and continues on as expected.
If I leave the ‘if’ code as-is, only ‘large’ is output, and the routine ends – even though the condition has not been met!
If I run that ‘if’ statement on its own, outside of the WHILE loop, it works just fine, responding true to a * in first 3 positions, and false for everything else…
What might I be doing wrong with this???
This variation seems to work.