说明:将html标签转换成特殊字符。例如将<script>转换成"<script>"javascript
$userInput = "不泄气、不抛弃、不放弃、不自弃;没有登不上的山,没有跨不过的坎儿,没有克服不了的困难。<script type=text/javascript;>alert('事虽微,不为不成;道虽迩,不行不至。');</script>"; $userInputEntities = htmlentities($userInput); echo $userInput; 输出结果: 不泄气、不抛弃、不放弃、不自弃;没有登不上的山,没有跨不过的坎儿,没有克服不了的困难。 echo $userInputEntities; 输出结果: 不泄气、不抛弃、不放弃、不自弃;没有登不上的山,没有跨不过的坎儿,没有克服不了的困难。 <script type=text/javascript;> alert('事虽微,不为不成;道虽迩,不行不至。'); </script>
说明:将htmlentities()函数转义过的字符串转成html标签。html
$str = "<p>从善如登,从恶如崩。</p>"; $a = htmlentities($str); $b = html_entity_decode($str); echo $a; 输出结果: <p>从善如登,从恶如崩。</p> echo $b; 输出结果: 从善如登,从恶如崩。