You must encode html objects:
you may try
htmlentities($str, ENT_QUOTES, "UTF-8");
Look here for full reference.
If you still have problems, sometimes you also need to decode the string using utf8_decode () so you can try:
$str = utf8_decode($str); $str = htmlentities($str, ENT_QUOTES);
source share