Search code examples
phphtml-entities

htmlentities returning empty string


The following code outputs an empty string. The cause is the "ó" in $text, but why? What characters does utf-8 encode then?

The problem is solved when using iso-8859-1, but I need to use utf-8, so what am I doing wrong?

<!doctype html>
<head>
  <meta charset="utf-8">
</head>

<body>
<?
$text = 'Hola ó Hola';
$text = htmlentities($text,ENT_QUOTES,'utf-8');
echo $text;
?>
</body>
</html>

Solution

  • Make sure you save your source file as UTf-8 if it contains the string. Else make sure that whatever is supplying the string supplies it as UTF-8.