dreamwest Posted March 2, 2011 Share Posted March 2, 2011 Whats the best way to remove <script> and <style> tags including the content between them? $txt = "html stuff <script>javascript stuff</script> html stuff <style>.co{color:red}</style>html"; if(preg_match('~<script(.*?)</script>~is', $txt)){ //remove <script> content from $txt } Link to comment https://forums.phpfreaks.com/topic/229339-remove-tags/ Share on other sites More sharing options...
Psycho Posted March 2, 2011 Share Posted March 2, 2011 $text = preg_replace("#<script[^>]*>.*?</script>#i", '', $text); $text = preg_replace("#<style[^>]*>.*?</style>#i", '', $text); Not tested, but I think it is right. Link to comment https://forums.phpfreaks.com/topic/229339-remove-tags/#findComment-1181675 Share on other sites More sharing options...
dreamwest Posted March 2, 2011 Author Share Posted March 2, 2011 Finally got it to work. Thanks $txt = preg_replace("~<script(.*?)</script>~is", '', $txt); Link to comment https://forums.phpfreaks.com/topic/229339-remove-tags/#findComment-1181705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.