×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Bob Ray
Added: Jul 16, 2015 10:12 PM
Modified: Jul 16, 2015 10:36 PM
Views: 12
Sanitize user input - recursive
  1. /* Original code by Mohit Madan @TheMohitMadan */f
  2. unction clean($input) {
  3.  
  4.     if (is_array($input)) {
  5.  
  6.         foreach ($input as $key => $val) {
  7.  
  8.             $output[$key] = clean($val);
  9.  
  10.             // $output[$key] = $this->clean($val);
  11.  
  12.         }
  13.  
  14.     } else {
  15.  
  16.         $output = (string) $input;
  17.  
  18.         // if magic quotes is on then use strip slashes
  19.  
  20.         if (get_magic_quotes_gpc()) {
  21.  
  22.             $output = stripslashes($output);
  23.  
  24.         }
  25.  
  26.         // $output = strip_tags($output);
  27.  
  28.         $output = htmlentities($output, ENT_QUOTES, 'UTF-8');
  29.  
  30.     }
  31.  
  32. // return the clean text
  33.  
  34.     return $output;
  35.  
  36. }