2013-08-16 53 views
1

我用PHP 5试过htmlentities()功能与此代码:为什么htmlentities功能不能正常工作?

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

而且只显示两个空白字符(即““)。这是为什么?我试图用另一个字符替换“u与diaeresis”字符,它的工作原理。我怎样才能得到那份工作呢?

+0

点击右键,查看页面查看源代码的工作。 – 2013-08-16 06:06:12

+0

是的,我的作品很好 –

+0

也许是一个编码问题。你尝试过'meta charset = utf-8'吗? – Nikitas

回答

2

使用的字符集为您给出的内容....如

$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

+0

我试过了,但它仍然不起作用。 – sl34x

+0

无论如何,谢谢。这是用ANSI编码的.php文件(默认情况下在Windows中使用记事本)。我改变了它,在php和apache配置中设置了UTF-8编码,现在全部正常。 – sl34x

0

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

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

而且我得到了

Produccin 

,但我解决它,添加此之后连接到数据库

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