Home > php教程 > PHP源码 > 用php过滤所有html标签属性

用php过滤所有html标签属性

PHP中文网
Release: 2016-05-25 17:14:09
Original
1296 people have browsed it

用php过滤所有html标签属性

//1,过滤所有html标签的正则表达式:
</?[^>]+>
 
//2,过滤所有html标签的属性的正则表达式:
$html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$html);
 
//3,过滤部分html标签的正则表达式的排除式(比如排除<p>,即不过滤<p>):
</?[^pP/>]+>
 
//4,过滤部分html标签的正则表达式的枚举式(比如需要过滤<a><p><b>等):
</?[aApPbB][^>]*>
 
//5,过滤部分html标签的属性的正则表达式的排除式(比如排除alt属性,即不过滤alt属性):
\s(?!alt)[a-zA-Z]+=[^\s]*
 
//6,过滤部分html标签的属性的正则表达式的枚举式(比如alt属性):
(\s)alt=[^\s]*
Copy after login


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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template