1bigbear Posted November 17, 2009 Share Posted November 17, 2009 I got some text, and in the text there are a couple of javascripts, <script language='JavaScript' type='text/javascript' src='http://site.com/gfsdgf.js'></script> <script language='JavaScript' type='text/javascript'></script> <noscript><a href=''></a></noscript> And <script language="JavaScript"> flowplayer('in_tvPlayer_0',{ durationColor: '',}); </script> How can I remove only this javascripts, and keep the rest of the text? Link to comment https://forums.phpfreaks.com/topic/181930-remove-javascripts/ Share on other sites More sharing options...
rajivgonsalves Posted November 17, 2009 Share Posted November 17, 2009 try this echo preg_replace("#<script[^>]+>.*?</script>|<noscript>.*?</noscript>#s", '' , $str); $str is the string that contains the html Link to comment https://forums.phpfreaks.com/topic/181930-remove-javascripts/#findComment-959590 Share on other sites More sharing options...
thebadbad Posted November 17, 2009 Share Posted November 17, 2009 Or shortened: $str = preg_replace('~<((?:no)?script)\b[^>]*>.*?</\1>~is', '', $str); Link to comment https://forums.phpfreaks.com/topic/181930-remove-javascripts/#findComment-959602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.