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.'" />';
以下は、inputタグの出力です。
あなたはどのブランドのシングルサーブコーヒーメーカーを所有していますか?#answer67627X49X1159other {display:none;}#answer67627X49X1159999 {display:none;}