Skip to content

Instantly share code, notes, and snippets.

@afzafri
Created January 17, 2020 01:43
Show Gist options
  • Save afzafri/73abed3dbc9c208eacf717ec0a25b3ed to your computer and use it in GitHub Desktop.
Save afzafri/73abed3dbc9c208eacf717ec0a25b3ed to your computer and use it in GitHub Desktop.
Replace all occurrences of JS script tags in string. Quick way but not the best to prevent XSS
<?php
$attack = "<script>alert('boom');</script>";
$sanitized = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $attack);
echo $sanitized;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment