PHP中的htmlspecialchars()函数如何使用及实例代码详解?
- 内容介绍
- 文章标签
- 相关推荐
本文共计4040个文字,预计阅读时间需要17分钟。
例子 + 把预定义的字符 + (小于) + 和 + (大于) + 转换为 HTML 实体:+ php$str=This is some bold/b>text.; echo specialchars($str); + 以上代码的 HTML 输出如下(查看源代码):+ !DOCTYPE This�is�some�bold/b>text.
实例
把预定义的字符 "<" (小于)和 ">" (大于)转换为 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>
以上代码的浏览器输出:
This is some <b>bold</b> text.
运行实例
定义和用法
htmlspecialchars() 函数把预定义的字符转换为 HTML 实体。
本文共计4040个文字,预计阅读时间需要17分钟。
例子 + 把预定义的字符 + (小于) + 和 + (大于) + 转换为 HTML 实体:+ php$str=This is some bold/b>text.; echo specialchars($str); + 以上代码的 HTML 输出如下(查看源代码):+ !DOCTYPE This�is�some�bold/b>text.
实例
把预定义的字符 "<" (小于)和 ">" (大于)转换为 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>
以上代码的浏览器输出:
This is some <b>bold</b> text.
运行实例
定义和用法
htmlspecialchars() 函数把预定义的字符转换为 HTML 实体。

