为什么htmlentities功能不正常?

时间:2013-08-16 06:02:49

标签: php html-entities

我用PHP代码尝试了htmlentities()函数:

<?php
 $string="Einstürzende Neubauten"; echo htmlentities($string);
?>

它只显示两个空格(即“”)。这是为什么?我试图用另一个替换“u with diaeresis”char并且它有效。我怎么能得到那份工作?

2 个答案:

答案 0 :(得分:2)

使用charset为您的给定内容....例如

 $res = htmlentities ( $string, ENT_COMPAT, 'UTF-8');

有关更多信息,请查看in the manual htmlentities()

您使用的是哪个PHP版本?

也许这可能是你的解决方案

 $string = mb_convert_encoding ($str , "UTF-8");
 // testing 
    var_dump($string);
 $res = htmlentities ( $string, ENT_COMPAT, 'UTF-8');
 // testing
    var_dump($res);

请参阅PHP manual

答案 1 :(得分:0)

当我将PHP版本从5.2升级到5.6时,我遇到了同样的问题。我写道:

$res = htmlentities("Producción", ENT_IGNORE);

我得到了

Produccin

但我解决了它,在连接数据库后添加了这个

mysqli_set_charset($idCon,'utf8'); 
相关问题