我在utf8编码时遇到问题。在wordpress数据库中,有很多表情符号,但当我编码时,它们就不再出现了。取而代之的是出现一个"?"。
你能帮我吗?我认为它来自utf8_encode
这是代码:
$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);
这是显示注释的行:
$jsonArray[$i][1] = utf8_encode(nl2br($row->comment_content));
我对编码口音没有问题,只对表情符号有问题
感谢
这就是我解决这个问题的方法:
创建一个函数
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;
}
调用函数
echo formatoAcentos($post['texto']);
我改进了它,因为它不起作用。
功能:
function formatoAcentos($texto) {
$nvotexto = nl2br($texto); // permite mantener el salto de línea
$nvotexto = utf8_encode($nvotexto); // permite caracteres especiales como los acentos
return $nvotexto;
}
函数调用。
echo formatoAcentos($row['descripcion_doc'])