在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教程》
以上就是php 如何转义 html?的详细内容。
