關于html_entity_decode在大多數情況下是與htmlspecialchars htmlentities配合使用的.
html_entity_decode用法:
string html_entity_decode(string $string [,int $quote_style = ENT_COMPAT [, string $charset ]]).
html_entity_decode() 函數把 HTML 實體轉換為字符.
html_entity_decode() 是 htmlentities() 的反函數也html_entity_decode() 是 htmlspecialchars() 的反函數.
- $str = "A 'quote' is bold www.companysz.com";
- Outputs: A 'quote' is <b>bold</b>
- $s = htmlspecialchars($str);
- echo $s;
- Outputs: A 'quote' is <b>boldwww.111cn.net</b>
- echo html_entity_decode($s);
- A 'quote' is bold
- $str = "John & 'Adams'";
- echo html_entity_decode($str);
- echo "
";- echo html_entity_decode($str, ENT_QUOTES);
- echo "
";- echo html_entity_decode($str, ENT_NOQUOTES);
- ?>//開源代碼Vevb.com
- //瀏覽器輸出:
- John & 'Adams'
- John & 'Adams'
- John & 'Adams'
如果在瀏覽器中查看源代碼,會看到這些 HTML:
- <html>
- <body>
- John & 'Adams'<br />
- John & 'Adams'<br />
- John & 'Adams'
- body>
- html>
新聞熱點
疑難解答