Home  >  Article  >  Backend Development  >  How does PHP escape HTML?

How does PHP escape HTML?

Guanhui
GuanhuiOriginal
2020-06-04 17:49:193836browse

How does PHP escape HTML?

PHP 如何转义 HTML?

在PHP中可以使用“htmlentities()”函数将HTML进行转义,该函数用于将字符转换为HTML转义字符,其语法是“htmlentities($str)”,其参数$str表示要转义的HTML字符串,返回值为编码后的字符。

示例

<?php
$str = "A &#39;quote&#39; is <b>bold</b>";

// 输出: A &#39;quote&#39; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// 输出: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

推荐教程:《PHP教程

The above is the detailed content of How does PHP escape HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn