2013-08-16 55 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'); 
相關問題