I want to remove HTML tags, also contents of style and script tag but my code is not removing style tag contents, don't know why. any idea about this ?
$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.'" />';
Following is the output in input tag.
Which brand(s) of single serve coffee brewer do you own? #answer67627X49X1159other {display:none;} #answer67627X49X1159999 {display:none;}