PHP 如何轉(zhuǎn)義 HTML?
在PHP中可以使用“htmlentities()”函數(shù)將HTML進(jìn)行轉(zhuǎn)義,該函數(shù)用于將字符轉(zhuǎn)換為HTML轉(zhuǎn)義字符,其語法是“htmlentities($str)”,其參數(shù)$str表示要轉(zhuǎn)義的HTML字符串,返回值為編碼后的字符。
示例
<?php $str = "A 'quote' is <b>bold</b>"; // 輸出: A 'quote' is <b>bold</b> echo htmlentities($str); // 輸出: A 'quote' is <b>bold</b> echo htmlentities($str, ENT_QUOTES); ?>
推薦教程:《PHP教程》