When htmlemtities() Is Failing

<?php

$string = "Café & 'quotes' and € euro";

// ISO-8859-1 mode
var_dump( htmlentities($string, ENT_QUOTES, "big5"));
// empty string

var_dump( htmlentities($string, ENT_QUOTES, "xxx"));
// default to utf8
// Caf&eacute; &amp; &#039;quotes&#039; and &euro; euro

By default, htmlentities() uses UTF-8. The third argument of that function is the actual encoding, so it is a parameter. When using a non-existing encoding, such as xxx, PHP detects it, and default to UTF-8 (here it works well).

On the other hand, when using a valid encoding, but that is not supported, PHP default to returning an empty string.

See Also

PHP Error Messages

PHP Features

Last updated: 13 August 2026