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

How to remove all HTML tags in PHP?

Guanhui
GuanhuiOriginal
2020-06-06 17:57:373972browse

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;);
?>

The above routine will output:

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

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!

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