Solved

Strip script tags

Posted on 2008-10-15
2
847 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now