Home > Backend Development > PHP Problem > How to remove all HTML tags in PHP?

How to remove all HTML tags in PHP?

Guanhui
Release: 2023-03-01 13:02:01
Original
3955 people have browsed it

How to remove all HTML tags in PHP?

How to remove all HTML tags in PHP?

In PHP, you can use the "strip_tags()" function to remove all HTML tags from the string. This function is used to remove HTML and PHP tags from the string. Its syntax is "strip_tags( str)", its parameter str represents the string to be operated on, and the return value is the processed character.

Example

strip_tags() Example

<?php
$text = &#39;<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>&#39;;
echo strip_tags($text);
echo "\n";
// 允许 <p> 和 <a>
echo strip_tags($text, &#39;<p><a>&#39;);
?>
Copy after login

The above routine will output:

Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>
Copy after login

Since strip_tags() cannot actually validate HTML, incomplete or broken tags will cause more data to be deleted.

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to remove all HTML tags in PHP?. 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