Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Strip script tags

Posted on 2008-10-15
Medium Priority
Last Modified: 2013-11-19

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>
Question by:dougbnv
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

Expert Comment

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


Accepted Solution

deresh earned 1000 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


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

609 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