Home >Backend Development >PHP Problem >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 = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'; echo strip_tags($text); echo "\n"; // 允许 <p> 和 <a> echo strip_tags($text, '<p><a>'); ?>
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!