— update —
Ok, I’ve narrowed this down to the keywords being checked, The keywords will only match with spaces between them if they are hard coded in to the array. If the keywords with spaces are placed in to the array are results from a database then the preg_match_all fails with 0 results found.
So if I hard code the array in php like
$myarray = array("This is my Phrase","This is my Second Phrase");
and then check it against the texttoscan the preg_match_all will find both phases, but
if i do this to create the array:
$result1 = mysql_result($result,$i,"firstphrase");
$result2 = mysql_result($result,$i,"secondphrase");
$myarray = array($result1,$result2);
The preg_match_all below will fail and not find the phrases, but if I populate the array with single words instead of phrases it will work. So I assume I have to prepare the strings that contain spaces that are returned from the database, but I’m not exactly sure how to do it, either that or I need to reformat the regex pattern?
foreach ($myarray as $K) {
$pattern = "/\b($K)\b/";
$count = preg_match_all($pattern, $texttoscan, $matches);
if($count > 0){ echo "matched"; }
}
Is it possible that the database text contains line breaks, where the hard-coded text didn’t? If so, you would want to use the
mmodifier to allow multi-line matching. That would make the regular expression:Hope that helps. Also, unless you are trying to specifically match UTF words/characters you shouldn’t have any problem with that.