Convert � � to Emoji in HTML using PHP

假装没事ソ 提交于 2019-11-28 01:16:08
Tyler F

I was not able to find a function to do this, but this works:

$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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!