PHP htmlentities()函數(shù)用法講解
PHP htmlentities() 函數(shù)
實(shí)例
把一些字符轉(zhuǎn)換為 HTML 實(shí)體:
<?php $str = "<© W3CSçh°°¦§>"; echo htmlentities($str); ?>
上面代碼的 HTML 輸出如下(查看源代碼):
<!DOCTYPE html> <html> <body> <© W3CSçh°°¦§> </body> </html>
上面代碼的瀏覽器輸出如下:
<© W3CSçh°°¦§>
定義和用法
htmlentities()函數(shù)把字符轉(zhuǎn)換為 HTML 實(shí)體。
提示: 要把 HTML 實(shí)體轉(zhuǎn)換回字符,請(qǐng)使用 html_entity_decode() 函數(shù)。
提示: 請(qǐng)使用 get_html_translation_table() 函數(shù)來(lái)返回 htmlentities() 使用的翻譯表。
語(yǔ)法
htmlentities( _string,flags,character-set,double_encode_ )


實(shí)例 1
把一些字符轉(zhuǎn)換為 HTML 實(shí)體:
<?php $str = "Jane & 'Tarzan'"; echo htmlentities($str, ENT_COMPAT); // Will only convert double quotes echo "<br>"; echo htmlentities($str, ENT_QUOTES); // Converts double and single quotes echo "<br>"; echo htmlentities($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'
實(shí)例 2
通過使用西歐字符集,把一些字符轉(zhuǎn)換為 HTML 實(shí)體:
<?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo htmlentities($str, ENT_QUOTES, "ISO-8859-1"); // Will only convert double quotes (not single quotes), and uses the character-set Western European ?>
上面代碼的 HTML 輸出如下(查看源代碼):
<!DOCTYPE html> <html> <body> My name is Øyvind Åsane. I'm Norwegian. </body> </html>
上面代碼的瀏覽器輸出如下:
My name is Øyvind Åsane. I'm Norwegian.
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
相關(guān)文章
PHP PDOStatement::getAttribute講解
今天小編就為大家分享一篇關(guān)于PHP PDOStatement::getAttribute講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-02-02
PHP數(shù)組的定義、初始化和數(shù)組元素的顯示實(shí)現(xiàn)代碼
這篇文章主要介紹了PHP數(shù)組的定義、初始化和數(shù)組元素的顯示實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-11-11
PHP實(shí)現(xiàn)網(wǎng)上點(diǎn)歌(二)
PHP實(shí)現(xiàn)網(wǎng)上點(diǎn)歌(二)...2006-10-10

