Home > Backend Development > PHP Tutorial > php中删除html标签里的属性(可用正则表达式)

php中删除html标签里的属性(可用正则表达式)

WBOY
Release: 2016-06-23 14:14:02
Original
1109 people have browsed it

比如代码如下:

$str = '<span style=\"font-family:\'Arial\',\'sans-serif\';font-size:9pt;\">test</span>';$str=stripslashes($str);echo htmlspecialchars($str)."<br/>";
Copy after login

希望输入的是:test
总之:不管$str里的标签内含有任何属性都去除掉,只保留标签本身。


回复讨论(解决方案)

$str = '


pad第一的内容133
内容1

asdasdkjasd内容
任意的链接
后茜
';
$str = preg_replace('~<([a-z]+?)\s+?.*?>~i','<$1>',$str);
highlight_string($str);
?>

$str = '<span style=\"font-family:\'Arial\',\'sans-serif\';font-size:9pt;\">test</span>';//$str=stripslashes($str);$str = preg_replace('#<([^>\s/]+)[^>]*>#','<$1>',$str);echo htmlspecialchars($str)."<br/>";
Copy after login

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