PHP中有没有办法将汉字转换为Unicode?
e.g. (??) convert to (買 ;嘢 ;)
Run Code Online (Sandbox Code Playgroud)
function chineseToUnicode($str){
//split word
preg_match_all('/./u',$str,$matches);
$c = "";
foreach($matches[0] as $m){
$c .= "&#".base_convert(bin2hex(iconv('UTF-8',"UCS-4",$m)),16,10);
}
return $c;
}
//Print result
$str = "????????????????????????Umbrella Movement ? Umbrella Revolution???2014?9?26????????????????????????60-70???????????????????????????????????????????????????????????????????????????2017????????2016?????????????????????????????????????????????";
echo chineseToUnicode($str);
Run Code Online (Sandbox Code Playgroud)
对于 Ryan(utf8 到 unicode + unicode 到 utf8)
PHP 中的完整示例代码