utf8_encode and Emoji

不打扰是莪最后的温柔 提交于 2020-01-07 02:25:33

问题


I have a problem utf8 encoding. In the wordpress database, there are many emojis but when I encode, they no longer appear. There is a "?" instead that appears.

Can you help me ? I think it comes from utf8_encode

here is the code :

$results = $connection->query($req) or die(Array());

$results->setFetchMode(PDO::FETCH_OBJ); 

$i = 0;
$jsonArray = Array();
while($row = $results->fetch()) {   

    $jsonArray[$i][0] = utf8_encode($row->comment_author);
    $jsonArray[$i][1] = utf8_encode(nl2br($row->comment_content));
    $jsonArray[$i][2] = utf8_encode($row->comment_date);
    $jsonArray[$i][3] = utf8_encode($row->replyingToAuthor);
    $jsonArray[$i][4] = utf8_encode($row->comment_ID);

    ++$i;
}

$results->closeCursor();
$connection = NULL;
echo json_encode($jsonArray);

This is the line that displays the comment:

 $jsonArray[$i][1] = utf8_encode(nl2br($row->comment_content));

I have no problem with encoding accents, only with emoji

Thank you


回答1:


This is what I did to solve this:

Create a function

function accents($texto) {
    $text = nl2br($text); // allows to have spaces in the text
    $text = utf8_encode($text); //allows to have accents and special characters
    return $text;
}

Call the function

echo formatoAcentos($post['texto']);


来源:https://stackoverflow.com/questions/37218910/utf8-encode-and-emoji

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