PHP的特殊字符,如ñ [英] php with special characters like ñ
问题描述
起初,我认为问题是,当我从一个ajax调用返回echo json_encode($ row)时,其结果为 - 变为NULL。但在测试之后,我发现问题在此之前就存在。
At first I thought the problem was when I return echo json_encode($row) from an ajax call that results with ñ are changed to NULL. But after testing I found out that the problem exists way before that.
在一个php文件示例中:
In a sample php file with:
$test = "Nuñez"
echo $test
<结果只是Nu ez
the result is just Nu�ez
我已经搜索过,但没有一个建议的解决方案工作。像:
I've searched around but none of the suggested solutions work. Like:
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
或< meta http-equiv =Content-Typecontent = text / html; charset = utf-8/>
或 header('content-type:text / html; charset:utf-8'); code>。还有一些我已经忘记的解决方案,相信我我尝试了很多。
or <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
, or header('content-type: text/html; charset: utf-8');
. And some more solutions that I've already forgotten, believe me I tried a lot.
这只是它的开始,我希望这不会是一个因为我的数据库是在utf-8中的问题,所以是我的$ mysqli字符集。但我认为我不能说ajax json_encode一样。但是没关系,一次只有一个问题。任何人都可以帮助我。非常感谢!
That's just the beginning of it, I'm hoping that won't be a problem with mysql since my database is in utf-8 so is my $mysqli charset. But I think I can't say the same for ajax json_encode. But nevermind, one problem at a time. Can anybody please help me. Thanks a lot!
问题已解决 我只需在Notepad ++中设置UTF-8编码因为它在Encode in ANSI之前。
PROBLEM SOLVED I just had to set "Encode in UTF-8" in Notepad++, as it was in "Encode in ANSI" before.
推荐答案
对于我
for me
$test = "Nuñez";
echo $test;
显示Nuñez
shows Nuñez
您可以尝试
You may try
$test = "Nuñez";
echo utf8_decode($test);
或
$test = utf8_encode("Nuñez");
echo utf8_decode($test);
这篇关于PHP的特殊字符,如ñ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!