PHP中如何使用htmlspecialchars()函数进行转义?

更新于
2026-09-23 07:51:47
0阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计4043个文字,预计阅读时间需要17分钟。

PHP中如何使用htmlspecialchars()函数进行转义?

实例 + 将预定义的字符 (小于)和 (大于)转换为 HTML 实体:+ php$+ str+=+ This+is+some+bbold+/b+text.+;+ echo+ specialchars($str)+ ;+ 以上代码的 HTML 输出如下(查看源代码):+ + + + This+is+some+bbold+/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 实体。

阅读全文

本文共计4043个文字,预计阅读时间需要17分钟。

PHP中如何使用htmlspecialchars()函数进行转义?

实例 + 将预定义的字符 (小于)和 (大于)转换为 HTML 实体:+ php$+ str+=+ This+is+some+bbold+/b+text.+;+ echo+ specialchars($str)+ ;+ 以上代码的 HTML 输出如下(查看源代码):+ + + + This+is+some+bbold+/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 实体。

阅读全文