Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with utf8 characters and htmlspecialchars in yii

I have a problem with the char encoding in yii. If I create a new webapp:

 ./Yii-framework/framework/yiic webapp MyTest

Then go to /protected/views/layouts/main.php and change the footer to a text with an utf8 character, for example

<div id="footer">
        Cópyrîgth <br />
</div>

Refresh the page and everything is ok. Nice! ;)

And then I try to log in with an utf8 character in the username, for example ádmin, it crashes saying:

Error 500

htmlspecialchars(): Invalid multibyte sequence in argument

So I checked this article about unicode in yii

and then I went to /protected/config/main.php and added this line at the start:

header('Content-Type: text/html; charset=utf-8');

Retrying the same login again it works (doesn't crash) but now the footer is broken and shows:

C�pyr�ght

I've tried other combinations like explained in the "Unicode in yii" article but none of them make both things work at the same time.

Any ideas for solving this problem?

Note: I can't change to the php.ini file.

I also tried the AddDefaultCharset UTF-8 option in the .htaccess file and put it in the folder at the /MyTest/ is that the correct folder referred in the article as: your DocumentRoot ?

Thanks

like image 374
Addev Avatar asked Jun 11 '12 21:06

Addev


1 Answers

I'm not at all familiar with yii, but, if you want to paste literal unicode characters into a file, you need to make sure that your text editor saves the file using a unicode encoding, such as utf8. Try utf8, without a BOM.

My experience is that text editors behave strange when you change the encoding setting and there's already encoded characters in it. Just start over with a fresh file, change the encoding, then paste the characters in.

like image 181
goat Avatar answered Sep 28 '22 03:09

goat