Why does the PHP function htmlentities(…) returns wrong results?
I have the following code : function testAccents() { $str = "àéè"; $html = htmlentities($str); echo $html; } When I run it, instead of getting àéè I get à éè . I thought that it could be a problem of encoding but the file is utf-8 : > file -bi PublicationTest.php text/x-c++; charset=utf-8 Why do I get this strange result ? EDIT: I use PHP 5.3. Before PHP 5.4.0, htmlentities() expects ISO-8859-1 data by default. It's interpreting your UTF-8 input as single-byte characters, which results in the funny results you get. Specify the encoding specifically. $html = htmlentities($str, ENT_COMPAT,