PHP html_entity_decode()函數(shù)講解
PHP html_entity_decode() 函數(shù)
實例
把 HTML 實體轉(zhuǎn)換為字符:
<?php $str = "<© W3CSçh°°¦§>"; echo html_entity_decode($str); ?>
上面代碼的 HTML 輸出如下(查看源代碼):
<!DOCTYPE html> <html> <body> <© W3CSçh°°¦§> </body> </html>
上面代碼的瀏覽器輸出如下:
<© W3CSçh°°¦§>
定義和用法
html_entity_decode() 函數(shù)把 HTML 實體轉(zhuǎn)換為字符。
html_entity_decode() 函數(shù)是htmlentities()
函數(shù)的反函數(shù)。
語法
html_entity_decode( _string,flags,character-se_ t)
實例 1
把一些 HTML 實體轉(zhuǎn)換為字符:
<?php $str = "Jane & 'Tarzan'"; echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes echo "<br>"; echo html_entity_decode($str, ENT_QUOTES); // Converts double and single quotes echo "<br>"; echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes ?>
上面代碼的 HTML 輸出如下(查看源代碼):
<!DOCTYPE html> <html> <body> Jane & 'Tarzan'<br> Jane & 'Tarzan'<br> Jane & 'Tarzan' </body> </html>
上面代碼的瀏覽器輸出如下:
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
實例 2
通過使用西歐字符集,把一些 HTML 實體轉(zhuǎn)換為字符:
<?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1"); ?> The HTML output of the code above will be (View Source): <!DOCTYPE html> <html> <body> My name is Øyvind Åsane. I'm Norwegian. </body> </html>
上面代碼的瀏覽器輸出如下:
My name is Øyvind Åsane. I'm Norwegian.
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
php學(xué)習(xí)之簡單計算器實現(xiàn)代碼
php學(xué)習(xí)之簡單計算器實現(xiàn)代碼,需要的朋友可以參考下。2011-06-06