【问题标题】:Get query return unicode symbols获取查询返回 unicode 符号
【发布时间】:2014-02-13 19:15:41
【问题描述】:

我使用 cURL,在得到查询后我收到下一个 html 代码:

$rezult = '<h5>\u0420\u0443\u0431\u0440\u0438\u043a\u0430:&lt;\/h5&gt;\n\t<select id="\&quot;category_2\&quot;" name="\&quot;category\&quot;" size="0" lev="\&quot;2\&quot;" onchange="\&quot;getCategory(this);\&quot;">\n\t            <option value="\&quot;213\&quot;" t="\&quot;child\&quot;" title="\&quot;\u041c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435" \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u044b\"="">\u041c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u0442\u0435\u043b\u0435\u0444\u043e\u043d\u044b&lt;\/option&gt;            </option><option value="\&quot;214\&quot;" t="\&quot;child\&quot;" title="\&quot;\u0410\u043a\u0441\u0435\u0441\u0441\u0443\u0430\u0440\u044b\&quot;">\u0410\u043a\u0441\u0435\u0441\u0441\u0443\u0430\u0440\u044b&lt;\/option&gt;></select></h5>'

如何将其转换为 UTF 8? PS:我试试

 mb_convert_encoding($rezult, "UTF-8);
 iconv('ASCII', 'UTF-8//IGNORE', $rezult);

但不是rezult。

我已经找到解决方案了:

function replace_unicode_escape_sequence($match) {
  return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
echo stripslashes(
html_entity_decode(
     preg_replace_callback('/\\\\u([\\da-f]{4})/i', 'replace_unicode_escape_sequence', $rezult)
  )
);

谢谢大家。

【问题讨论】:

  • 记得关闭"UTF-8"

标签: php curl unicode encoding utf-8


【解决方案1】:
$rezult = utf8_encode($rezult);

【讨论】:

    猜你喜欢
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多