php html_entity_decode() 適用于PHP 4.3.0+,將HTML 實體轉成字符。
html_entity_decode(包含HTML 實體的字符串, 可選如何解碼引號, 可選字符編碼集)
如果字符串中包含無法被識別的字符集將被忽略,并由 ISO-8859-1 代替。您可以使用PHP htmlentities()將HTML標簽、引號及ASCII字符集外的其他字符串轉換成HTML 實體。
如何解碼引號:
ENT_COMPAT - 默認。僅解碼雙引號。
ENT_QUOTES - 解碼雙引號和單引號。
ENT_NOQUOTES - 不解碼任何引號。
字符編碼集:
ISO-8859-1 - 默認。西歐。
ISO-8859-15 - 西歐 (增加 Euro 符號以及法語、芬蘭語字母)。
UTF-8 - ASCII 兼容多字節 8 比特 Unicode
cp866 - DOS 專用 Cyrillic 字符集
cp1251 - Windows 專用 Cyrillic 字符集
cp1252 - Windows 專用西歐字符集
KOI8-R - 俄語
GB2312 - 簡體中文,國家標準字符集
BIG5 - 繁體中文
BIG5-HKSCS - Big5 香港擴展
Shift_JIS - 日語
EUC-JP - 日語
PHP htmlspecialchars()把 & ' " < 和 > 轉換成HTML 實體
PHP htmlspecialchars_decode()把 & ' " < 和 > HTML 實體反轉成字符
PHP htmlentities()把HTML標簽字符轉換為 HTML 實體
PHP html_entity_decode() 將所有HTML 實體轉成字符原型
PHP html_entity_decode() 實例雖然使用PHP htmlentities() 只能對HTML標簽字符串進行HTML 實體化,但是您可以使用PHP html_entity_decode() 對所有HTML 實體化的字符進行轉換成字符。
<?phpfunction showCode($s){return str_replace('&', '&', $s);}// 由于轉成HTML實體后,輸出依舊是原字符,所以這里對 & 替換成 & 可以輸出源代碼格式,如果不用這個替換,您可以通過查看輸出的 $html 源代碼,能夠看到一樣的結果。$weigeti = '-->"E.V-Get.com"<--';$html = htmlentities($weigeti, ENT_QUOTES);echo showCode($html);// 輸出【-->"E.V-Get.com"<--】$entity = html_entity_decode($html);echo showCode($entity);// 輸出【-->"E.V-Get.com"<--】$entity_noquotes=html_entity_decode($html, ENT_NOQUOTES);echo showCode($entity_noquotes);// 輸出【-->"E.V-Get.com"<--】?>
原文:http://e.v-get.com/w3c/PHP_html_entity_decode.html
新聞熱點
疑難解答