-2
I have a function that compares 2 words, but when removing the accents, it still identifies as different words:
function acento($str, $from, $to) {
$keys = array();
$values = array();
preg_match_all('/./u', $from, $keys);
preg_match_all('/./u', $to, $values);
$mapping = array_combine($keys[0], $values[0]);
return strtr($str, $mapping);
}
$from = "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ";
$to = "aaaaeeiooouucAAAAEEIOOOUUC";
foreach($items as $i){
$query=acento($_POST['item'], $from, $to);
$n = mb_strlen($_POST['item'],'utf8');
$q=acento($i, $from, $to);
$q=substr($q,0,$n);
if($query==$q) {
echo 'teste'; echo "<div style='border-bottom: 1px solid #ccc;margin-bottom:3px'><button type='button' value='{$i}' class='getdemanda uk-button uk-button-text uk-button-large' style='font-size:20px'>{$i}</button></div>";
}else{
var_dump($q,$query);
echo '<br/>';
}
}
When I make a if($q==$query)
it gives false result, even in var dump giving exactly the same thing to the two.
Example of var_dump($q==$query
) with text "copy"
STRING(4) "COPI" STRING(4) "COPI"
What is the content of
$_POST['item']
?– Benilson
What’s in the
$items
?– Sam