views:

95

answers:

3

Hi there,

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.

A: 

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, which might explain why things go haywire when it meets multibyte characters.

Tatu Ulmanen
Line 207 is here.$charset = 'UTF-8';htmlspecialchars($text, ENT_QUOTES, $charset); // Line 207
lakum4stackof
A: 

You are feeding corrupted character data into the function, or not specifying the right encoding.

I had this issue a while ago, old behavior (prior to PHP 5.2.7 I believe) was to return the string despite corruption, but since that version it will throw this error instead.

My solution involved writing a script to feed my strings through iconv using the //IGNORE modifier to remove corrupted data.

(We had a corrupted database which had some strings in UTF-8, some in latin-1 usually with incorrectly defined character types on the columns).

(Looking at the comment to Tatu's answer, I would start by looking at (and playing with) the contents of the $charset variable.

berty
I agree. I've passed user data through iconv or mb_convert_encoding(), with the 'from' and 'to' charsets the same. There's usually an option to strip invalid characters.
Jeff Standen
A: 

Thats actually one of the most frequent errors i get

sometimes i dont use __() translation - just plain "german" text containing äöü

if you dont save it as utf8, you get in trouble

details: here

mark