Search code examples
phpcakephpwarningshtmlspecialchars

htmlspecialchars(): Invalid multibyte sequence in argument


I am getting this error in my local site.

Warning (2): htmlspecialchars(): Invalid multibyte sequence in argument in [/var/www/html/cake/basics.php, line 207]

Does anyone knows, what is the problem or what should be the solution for this?

Thanks.


Solution

  • Be sure to specify the encoding to UTF-8 if your files are encoded as such:

    htmlspecialchars($str, ENT_COMPAT, 'UTF-8');
    

    The default charset for htmlspecialchars is ISO-8859-1 (as of PHP v5.4 the default charset was turned to 'UTF-8'), which might explain why things go haywire when it meets multibyte characters.