php - 修复 PHP 中的字符

标签 php html encoding utf-8 character-encoding

有人知道这是什么以及如何解决它吗? “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>

这似乎是一个问题,因为在解码之前我必须在 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;}

最佳答案

看看这个页面

Unicode-friendly PHP and MySQL

在此页面上,您将找到有关 UTF-8 编码的简单明了的解释以及如何在您的网站中应用它以及一些实际示例。

您还需要确保使用 UTF-8 编码(无 BOM)保存文件。

关于php - 修复 PHP 中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5155898/

相关文章:

php - 这个 MySQL 查询有什么问题。它给出了无效的参数编号错误

java - 如何通过 Android 应用程序与外部 SQL 数据库通信?

html - 对齐内容底部的页脚,推到侧边栏的右侧

python邮件编码解码问题

PHP - 如何将数组发送到另一个页面?

PHP 如何创建一个名为 "do"的函数?

javascript - 无法在某个高度维度垂直滚动到表单顶部

html - 响应式设计适用于移动设备,但在调整屏幕大小时不适应

java - 在 JTable 中显示 Emoji 字符

Java:多平台字符串编码问题