The php strip_tags function work well for plain html codes but have problem dealing with css codes and javascripts like the following <style type="text/css"> .dap_category { margin-bottom:3px; font-size:11px; font-weight:bold; color:#424242; min-height:15px; } .dap_image_box { min-height:110px; } .dap_no_image { border:solid thin black; width:80px; height:60px; padding-top:20px; margin:0 auto } .dap_image { border:solid thin black; } .dap_item { margin-top:5px; margin-bottom:2px; } a.dap_item_link { color:black; font-size:11px; font-weight:bold } .dap_item_price { font-size:11px; font-weight:bold; color:#B40404; } </style> Code (markup): strip_tags remove only <style type="text/css"> and </style> but didn't remove the entire css code... Any way to solve this problem? thanks
try regular expressions then: $code = '<style type="text/css"> .dap_category { margin-bottom:3px; font-size:11px; font-weight:bold; color:#424242; min-height:15px; } .dap_image_box { min-height:110px; } .dap_no_image { border:solid thin black; width:80px; height:60px; padding-top:20px; margin:0 auto } .dap_image { border:solid thin black; } .dap_item { margin-top:5px; margin-bottom:2px; } a.dap_item_link { color:black; font-size:11px; font-weight:bold } .dap_item_price { font-size:11px; font-weight:bold; color:#B40404; } </style>'; $code = eregi_replace('<style type="text/css">(.*)</style>', '', $code); echo $code; Code (markup):
This should remove <style/> or <script/> elements. $str = preg_replace('#<(script|style)[^>]*>.+</\1>#Usi', '', $str); PHP:
I dunno what Us means, if it means that it should be non-greedy. Otherwise I suggest this: $str = preg_replace('#<(script|style)[^>]*>.+?</\1>#i', '', $str); PHP: