You should encode html entities:
you could try
htmlentities($str, ENT_QUOTES, "UTF-8");
Look here for a complete reference
If you still have problems sometimes you also have to decode the string with utf8_decode()
so you can try:
$str = utf8_decode($str);
$str = htmlentities($str, ENT_QUOTES);