实例
把预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体:
<?php $str = "This is some <b>bold</b> text."; echo htmlspecialchars($str); ?>
以上代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html> <html> <body> This is some <b>bold</b> text. </body> </html>
本文介绍了一个PHP代码示例,展示了如何使用htmlspecialchars函数将预定义的HTML特殊字符转换为HTML实体,以防止潜在的安全威胁。
把预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体:
<?php $str = "This is some <b>bold</b> text."; echo htmlspecialchars($str); ?>
以上代码的 HTML 输出如下(查看源代码):
<!DOCTYPE html> <html> <body> This is some <b>bold</b> text. </body> </html>

被折叠的 条评论
为什么被折叠?