Skip to content

Instantly share code, notes, and snippets.

@remoharsono
Last active November 22, 2019 12:10
Show Gist options
  • Save remoharsono/627857888e7e0bdbb45e9223c41d0ac9 to your computer and use it in GitHub Desktop.
Save remoharsono/627857888e7e0bdbb45e9223c41d0ac9 to your computer and use it in GitHub Desktop.
Sample script removing script and applet tag from HTML document
<?php
require 'vendor/autoload.php';
$html = "<!DOCTYPE html><html><head><title>.</title></head><body><h1>Welcome to the jungle</h1><script>var x=10;</script><script>alert('this is an alert');</script></body></html>";
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.ForbiddenElements', array('script','applet'));
$purifier = new HTMLPurifier($config);
$clean= $purifier->purify($html);
echo $clean;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment