ghazi ghazi - 4 months ago 14
PHP Question

str_replace with htmlspecialchars return empty result

I want to replace all special character (in array), I used htmlspecialchars, but it does not work I found empty result !!

this is my instruction:



str_replace( array('è','é','ê','ë'),
array('e','e','e','e'),
htmlspecialchars(strtolower("Elément")) );





thank's for helping...

Answer Source

Short answer: you must use mb_strtolower instead strtolower,

run the snippet below you will find why:

<?php

$a = str_replace( array('è','é','ê','ë'), array('e','e','e','e'), htmlspecialchars(strtolower("Elément")) );

echo "\n0.".$a;
echo "\n1.".htmlspecialchars(strtolower("Elément"));
echo "\n2.".strtolower("Elément");
echo "\n3.".mb_strtolower("Elément");
echo "\n4.".htmlspecialchars(mb_strtolower("Elément"));

$a = str_replace( array('è','é','ê','ë'), array('e','e','e','e'), htmlspecialchars(mb_strtolower("Elément")) );


echo "\n5.".$a;

see also enter link description here