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
Solved

Strip script tags

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

856 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