Solved

Strip script tags

Posted on 2008-10-15
2
863 Views
Last Modified: 2013-11-19
Hi

I want to strip all javascript from text with php eg:

Original = Text and other <a href = \"#\">html</a><script>blaha</script><B>blah</B>

Stripped = Text and other <a href = \"#\">html</a><B>blah</B>
0
Comment
Question by:dougbnv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 6

Expert Comment

by:deresh
ID: 22720320
use preg_replace like this:
$src = 'Text and other <a href = \"#\">html</a><script>blaha</script><B>blah</B>';
$cleaned = preg_replace("(<script>.*<\/script>)","",$src);

Open in new window

0
 
LVL 6

Accepted Solution

by:
deresh earned 250 total points
ID: 22720348
this is more accurate (it works for not empty <script> and is case insensitive):
$cleaned = preg_replace("/(<script.*>.*<\/script>)/i","",$src);

Open in new window

0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
This video teaches users how to migrate an existing Wordpress website to a new domain.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question