修复 PHP 中的字符
有人知道这是什么以及如何解决它吗? “天哪”
<p>After 32 years in its former location, this popular restaurant
and bar moved to the bottom of the Avalon Bay Luxury residential building
that's just a walk from Angel Stadium. Modern and welcoming, the expansive
space is where fans, locals and families gather for upscale twists on classic
American dishes. Burgers here have a decidedly fun flair like “The OMG�
that is a burger surely meant for sharing (with many)--it's so huge that it's
served on a 14-inch bun. The restaurant also specializes in seafood with such
items as Chilean sea bass, mahi mahi and swordfish. The lounge also serves
signature drinks like the Rally Monkey Martini in tribute to the mascot
of the Angels.</p>
这似乎是一个问题,因为我必须在解码 JSON 数据之前运行一个函数,否则 JSON 解码将失败:
function safeJSON_chars($data) {
$aux = str_split($data);
foreach($aux as $a) {
$a1 = urlencode($a);
$aa = explode("%", $a1);
foreach($aa as $v) {
if($v!="") {
if(hexdec($v)>127) {
$data = str_replace($a,"&#".hexdec($v).";",$data);
}
}
}
}
return $data;}
Anyone know what this is and how to fix it? “The OMG�
<p>After 32 years in its former location, this popular restaurant
and bar moved to the bottom of the Avalon Bay Luxury residential building
that's just a walk from Angel Stadium. Modern and welcoming, the expansive
space is where fans, locals and families gather for upscale twists on classic
American dishes. Burgers here have a decidedly fun flair like “The OMG�
that is a burger surely meant for sharing (with many)--it's so huge that it's
served on a 14-inch bun. The restaurant also specializes in seafood with such
items as Chilean sea bass, mahi mahi and swordfish. The lounge also serves
signature drinks like the Rally Monkey Martini in tribute to the mascot
of the Angels.</p>
This seems to a problem because of a function I have to run on the JSON data before decoding it or JSON decoding will fail:
function safeJSON_chars($data) {
$aux = str_split($data);
foreach($aux as $a) {
$a1 = urlencode($a);
$aa = explode("%", $a1);
foreach($aa as $v) {
if($v!="") {
if(hexdec($v)>127) {
$data = str_replace($a,"".hexdec($v).";",$data);
}
}
}
}
return $data;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看看这个页面
Unicode 友好的 PHP 和 MySQL
在此页面上,您将找到 UTF-8 编码的简单明了的解释以及如何在您的网站中应用它以及一些实际示例。
您还需要确保使用 UTF-8 编码(无 BOM)保存文件。
Have a look at this page
Unicode-friendly PHP and MySQL
On this page you will find an easy and clear explaination of UTF-8 encoding and how to apply this in your websites along with some practical examples.
You will also need to make sure that your files are saved using UTF-8 encoding (without BOM).
在 PHP 中,您可以设置页面字符集:
In PHP, you can set the page charset:
您的字符集是否设置为 Latin1?尝试使用 UTF-8 并查看是否可以解决问题。
Is your character-set set to Latin1 perhaps? Try using UTF-8 and see if that fixes it.
这些将是 Unicode utf-8 中的 microsoft 引用。
Those would be microsoft quotes in Unicode utf-8.
我发现这很有帮助:
str_replace() 等效项对于像 UTF-8 这样的多字节字符串
然后像这样使用它:
I found this helpful:
str_replace() equivalent for Multi-byte string like UTF-8
Then use it like this: