Error with utf8 characters and htmlspecialchars in

2019-02-23 01:42发布

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

7条回答
【Aperson】
2楼-- · 2019-02-23 02:22

For htmlspecialchars problem check this answer: https://stackoverflow.com/a/3803972/133408

You have to specify encoding as 3rd parameter of htmlspecialchars

查看更多
登录 后发表回答