正则表达式如何过滤HTML标签中的属性值
2个回答
展开全部
1、过滤所有html标签的属性的正则表达式:
$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 JavaScript
"'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'([\r\n])[\s]+'", // 去掉空白字符
"'&(quot|#34);'i", // 替换 HTML 实体
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i"
); // 作为 PHP 代码运行
$replace = array ("","","\\1","\"","&","<",">"," ");
$html = preg_replace($search, $replace, $html);
顶
$search = array ("'<script[^>]*?>.*?</script>'si", // 去掉 JavaScript
"'<[\/\!]*?[^<>]*?>'si", // 去掉 HTML 标记
"'([\r\n])[\s]+'", // 去掉空白字符
"'&(quot|#34);'i", // 替换 HTML 实体
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i"
); // 作为 PHP 代码运行
$replace = array ("","","\\1","\"","&","<",">"," ");
$html = preg_replace($search, $replace, $html);
顶
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询