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

How does PHP escape HTML?

Guanhui
Release: 2023-03-01 11:52:02
Original
3885 people have browsed it

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);
?>
Copy after login

推荐教程:《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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template