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é & 'quotes' and € 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
- utf8, big5 and xxx [Try me]
PHP Error Messages
PHP Features
Last updated: 10 September 2026