我想删除 HTML 标签,还有样式和脚本标签的内容,但我的代码没有删除样式标签内容,不知道为什么。有什么想法吗?
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@si', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
$htmlstring = 'Which brand(s) of single serve coffee brewer do you own? <style type="text/css"> #answer67627X49X1159other {display:none;}</style>';
$htmlstring .= '<style> #answer67627X49X1159999 {display:none;}</style><script>alert(123);</script>';
$htmlstring = preg_replace($search,'',$htmlstring);
echo '<input style="width:90%" type="text" value="'.$htmlstring.'" />';
以下是输入标签中的输出。
您拥有哪些品牌的单杯咖啡机?#answer67627X49X1159other {display:none;} #answer67627X49X1159999 {display:none;}