修复PHP中的字符 [英] Fix characters in PHP
本文介绍了修复PHP中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道这是什么,如何解决它? OMG
< p>在其前位置32年后,这个受欢迎的餐厅
酒吧移动到Avalon Bay豪华住宅建筑
的底部,只是从天使体育场散步。现代和欢迎,膨胀
空间是球迷,当地人和家庭聚集在高档扭曲经典
美国菜。汉堡在这里有一个非常有趣的天赋像OMG的
,这是一个汉堡肯定意味着分享(许多) - 它是如此之大,它的
供应14英寸面包。餐厅还专营海产品,包括智利鲈鱼,马尾马枪和剑鱼等。休息室还供应
签名饮料,如Rally Monkey Martini,向天使的吉祥物
献礼。< / 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;}
解决方案
查看此页
在此页面上,您将看到一个简单明了的UTF-8编码说明,以及如何在您的网站中应用此编码以及一些实际示例。
您还需要确保使用UTF-8编码(不含BOM)保存文件。
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 funciton 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;}
解决方案
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中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文