I am using HTML Purifier (http://htmlpurifier.org/)
I just want to remove <script>
tags only.
I don't want to remove inline formatting or any other things.
How can I achieve this?
One more thing, it there any other way to remove script tags from HTML
This is a simplified variant of Dejan Marjanovic's answer:
Can be used to remove any kind of tag, including
<script>
:Use the PHP
DOMDocument
parser.This worked me me using the following HTML document:
Just bear in mind that the
DOMDocument
parser requires PHP 5 or greater.use the str_replace function to replace them with empty space or something
?>
Shorter:
$html = preg_replace("/<script.*?\/script>/s", "", $html);
When doing regex things might go wrong, so it's safer to do like this:
$html = preg_replace("/<script.*?\/script>/s", "", $html) ? : $html;
So that when the "accident" happen, we get the original $html instead of empty string.