Tyl*_*r F 6 php decode utf-8 utf-16 htmldecode
我们有一堆代理对(或2字节utf8?)字符,例如��祈祷手表情符号存储为UTF8为2个字符.在浏览器中呈现时,此字符串呈现为两个?
例如:
我需要使用php将这些转换为手emjoi,但我根本无法找到iconv,utf8_decode,html_entity_decode等的组合将其拉下来.
这个网站��正确转换:
http://www.convertstring.com/EncodeDecode/HtmlDecode
在那里粘贴以下字符串
Please join me in this prayer. ��❤️
你会注意到surragate对 (��)转换为
这个网站声称使用HTMLDecode,但我找不到任何内部的PHP来解决这个问题.我试过:iconv html_entity_decode和一些公共库.
我承认在转换字符编码方面我不是专家!
我无法找到执行此操作的函数,但这有效:
$str = "Please join me in this prayer. ��❤️";
$newStr = preg_replace_callback("/&#.....;&#.....;/", function($matches){return convertToEmoji($matches);}, $str);
print_r($newStr);
function convertToEmoji($matches){
$newStr = $matches[0];
$newStr = str_replace("&#", '', $newStr);
$newStr = str_replace(";", '##', $newStr);
$myEmoji = explode("##", $newStr);
$newStr = dechex($myEmoji[0]) . dechex($myEmoji[1]);
$newStr = hex2bin($newStr);
return iconv("UTF-16BE", "UTF-8", $newStr);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1633 次 |
| 最近记录: |