How to remove html with php regular expression

藏色散人
Release: 2023-03-05 13:58:02
Original
2738 people have browsed it

php regular expression method to remove html: first use "htmlspecialchars_decode" to convert the special HTML entities back to ordinary characters; then use the regular expression "preg_replace('/<\>] >/' ,'',$_str);" can be removed.

How to remove html with php regular expression

Recommended: "PHP Video Tutorial"

php regular removal of html tags

The code is as follows:

$_str = htmlspecialchars_decode($_str);             
 
$_str = preg_replace(&#39;/<\/?[^>]+>/&#39;,&#39;&#39;,$_str);
Copy after login

htmlspecialchars_decode - Convert special HTML entities back to ordinary characters

preg_replace function performs a regular expression search and replacement.

The above is the detailed content of How to remove html with php regular expression. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!