yii中的utf8字符和htmlspecialchars错误 [英] Error with utf8 characters and htmlspecialchars in yii
问题描述
我在yii中的char编码有问题。
如果我创建了一个新的webapp:
./Yii-framework/framework/yiic webapp MyTest
然后转到/protected/views/layouts/main.php并将页脚更改为带有utf8字符的文本,例如
< div id =footer>
Cópyrîgth< br />
< / div>
刷新页面,一切正常。尼斯! ;)
然后我尝试使用用户名中的utf8字符登录,例如ádmin,它崩溃说:
错误500
htmlspecialchars():参数中的多字节序列无效
,然后我转到 /protected/config/main.php 这行开头:
header('Content-Type:text / html; charset = utf-8');
重试相同的登录名,它工作正常(不会崩溃),但现在页脚被破坏, :
C pyr ght
我尝试过其他组合,如Unicode in yii文章中所解释的,但是没有一个可以同时工作。
有关解决此问题的任何想法吗?
注意:我无法更改为php.ini文件。
我还尝试了.htaccess文件中的 AddDefaultCharset UTF-8 选项,并将其放在/ MyTest /的文件夹中,这是文章中引用的正确文件夹: DocumentRoot ?
感谢
解决方案我不太熟悉yii ,但是,如果要将文本unicode字符粘贴到文件中,则需要确保文本编辑器使用unicode编码保存文件,例如utf8。尝试utf8,没有BOM。
我的经验是,当您更改编码设置,并且已经有编码字符时,文本编辑器表现得很奇怪。只需重新开始一个新的文件,更改编码,然后粘贴字符。
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
解决方案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.
这篇关于yii中的utf8字符和htmlspecialchars错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!