Do you want to remove accents and let lowercase? If it is, the Lower() function does it for you. After that, you have to run preg_replace for every word (otherwise it would only give match if the two words were followed both in the post when in the dados_mysql), then you have to make a explode. The findWords() function does this for you.
Do it like this:
function lower($string) {
$string = mb_strtolower($string, 'UTF-8');
$string = preg_replace('/[`´^~\'"]/', null, iconv( 'UTF-8', 'ASCII//TRANSLIT', $string ) );
return $string;
}
function findWords($string1, $string2) {
$stringLow1 = lower($string1);
$stringLow2 = lower($string2);
$stringLow1 = explode(" ", $stringLow1);
foreach ($stringLow1 as $string) {
$stringLow2 = preg_replace("/($string?)/i","<b>\\0</b>", $stringLow2);
}
$string2 = explode(" ", $string2);
$stringLow2 = explode(" ", $stringLow2);
foreach ($stringLow2 as $key => $string) {
if (preg_match("/<b>/", $string)) {
$string2[$key] = '<b>' . $string2[$key] . '</b>';
}
}
$string2 = implode(" ", $string2);
return $string2;
}
$dados_mysql = "seleção brasileira de futebol";
$digitado = "seleção de futebol";
echo findWords($digitado, $dados_mysql);
Note: analyzed the possibility of doing this in the Front-end? This is my suggestion.
Post the full code.
– Sr. André Baill
I put a response, I used another function. Take a look
– Sr. André Baill