在PHP中将Unicode字符转换为文本不起作用 [英] Converting Unicode character to text in PHP is not working

查看:41
本文介绍了在PHP中将Unicode字符转换为文本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Unicode字符转换为PHP中的文本。但是字符串是Unicode字符和文本的混合。

I am trying to convert Unicode character to text in PHP. But the string is the mixture of Unicode characters and text. But it is not working.

我点击了此链接( PHP字符串中的Unicode字符

<?php

   $unicodeChar = "{'singer': u'', 'name': u'\\\\u101c\\\\u1031\\\\u1011\\\\u1032\\\\u101c\\\\u103d\\\\u103e\\\\u1004\\\\u1037\\\\u103a\\\\u101c\\\\u102d\\\\u102f\\\\u1000\\\\u103a'}\\r\\n\\r\\n    artist          : Thar Gyi\\r\\n    album           : Sal Pone Ta Pone\\r\\n    genre           : R&B\\r\\n    copyright       : MyanmarSongs.NET\\r\\n    track           : 1\\r\\n    title           : Lay Htal Hlwint Lite";
   echo json_decode('"'.$unicodeChar.'"');
   echo mb_convert_encoding($unicodeChar, 'UTF-8', 'HTML-ENTITIES'); 
   echo mb_convert_encoding($unicodeChar, 'UTF-8', 'UTF-16BE'); showing nothing

?>

当上述值是Unicode字符和文本(如我所用)的混合时,上述所有方案均不起作用。但是当值如此简单时,它就起作用了:

All the above scenarios are not working when the value is the mixtures of Unicode characters and text like I used. But it is working when the value is so simple like this:

$unicodeChar = '\u1000';
echo json_decode('"'.$unicodeChar.'"');

我该如何实现?

推荐答案

使用以下代码

$unicodeChar = '\u1000';
echo json_decode('"'.$unicodeChar.'"');

这篇关于在PHP中将Unicode字符转换为文本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆