2012-01-18 18 views
0

如何'請'htmlentities()不要轉換某些符號?例如,如何不不使用htmlentities()來轉換某些符號?

PHP,

<?php echo htmlentities(file_get_contents('fonts.css'),ENT_QUOTES);?> 

fonts.css,

@font-face { 
    font-family: 'ChunkFiveRoman'; 
    src: url('chunkfive-webfont.eot'); /* EOT file for IE */ 
    src: local('☺'), url('chunkfive-webfont.ttf') format('truetype'); /* TTF file for CSS3 browsers */ 
} 

結果,

@font-face { 
    font-family: 'ChunkFiveRoman'; 
    src: url('chunkfive-webfont.eot'); /* EOT file for IE */ 
    src: local('�'), url('chunkfive-webfont.ttf') format('truetype'); /* TTF file for CSS3 browsers */ 
} 

我想要保持 '☺',因爲它是,但不轉換它變成' º'。

可能嗎?

+2

'htmlentities'不能像那樣工作,所以問題在其他地方。也許你的css文件是用utf-8編碼的,但是你用單字節編碼將它顯示爲HTML? – Jon 2012-01-18 17:23:55

+0

謝謝喬恩。可能我以單字節編碼的形式將css顯示爲HTML ......但現在似乎馬里奧的答案可以正常工作。 – laukok 2012-01-18 17:32:53

回答

2

使用htmlentities的第三個參數。它指定字符集:

<?php echo htmlentities(file_get_contents('fonts.css'),ENT_QUOTES,"UTF-8");?> 

這樣可以避免將笑臉轉換爲Latin-1字節等價物。 (這看起來像什麼)。

+0

感謝馬里奧!有用! :-) – laukok 2012-01-18 17:30:18

相關問題