Home >Backend Development >PHP Problem >How does PHP escape HTML?
PHP 如何转义 HTML?
在PHP中可以使用“htmlentities()”函数将HTML进行转义,该函数用于将字符转换为HTML转义字符,其语法是“htmlentities($str)”,其参数$str表示要转义的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教程》
The above is the detailed content of How does PHP escape HTML?. For more information, please follow other related articles on the PHP Chinese website!