Advertisement
oscarholmedo

PHP Clean text input

Apr 12th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. function cleanInput($input) {
  3.  
  4.   $search = array(
  5.     '@<script[^>]*?>.*?</script>@si',   // Strip out javascript
  6.     '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags
  7.     '@<style[^>]*?>.*?</style>@siU',    // Strip style tags properly
  8.     '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments
  9.   );
  10.  
  11.     $output = preg_replace($search, '', $input);
  12.     return $output;
  13.   }
  14. ?>
  15. <?php
  16. function sanitize($input) {
  17.     if (is_array($input)) {
  18.         foreach($input as $var=>$val) {
  19.             $output[$var] = sanitize($val);
  20.         }
  21.     }
  22.     else {
  23.         if (get_magic_quotes_gpc()) {
  24.             $input = stripslashes($input);
  25.         }
  26.         $input  = cleanInput($input);
  27.         $output = mysql_real_escape_string($input);
  28.     }
  29.     return $output;
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement