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, "UTF-8");
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With