Advertisement
Guest User

Untitled

a guest
Jan 29th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2. $input = "ATTT";
  3. $whitelist = "abcdefghijklmnopqrstuvwxyz";
  4.  
  5. //Get an array of whitelist characters
  6. $whitelistLength = strlen($whitelist);
  7.  
  8. $i = 0;
  9.  
  10. //Assign a slot for each character in a whitelist
  11. while ($i < $whitelistLength)
  12. {
  13.     $whitelistArray[$i] = substr($whitelist, $i, 1);
  14.     $i++;
  15. }
  16.  
  17. //Remove the non-whitelist characters from the string
  18. $inputLength = strlen($input);
  19.  
  20. $i = 0;
  21.  
  22. //Turn the input string into an array
  23. while ($i < $inputLength)
  24. {
  25.     $inputArray[$i] = substr($input, $i, 1);
  26.     $i++;
  27. }
  28. print_r($inputArray);
  29.  
  30. //If the character isn't in the whitelist array then remove it
  31. $i = 0;
  32.  
  33. foreach ($inputArray as $key => $value)
  34. {
  35.     foreach ($whitelistArray as $key2 => $value2)
  36.     {
  37.         if (in_array($value, $whitelistArray))
  38.         {
  39.             //Do nothing, check passed
  40.         }
  41.         else
  42.         {
  43.             unset($inputArray[$key]);
  44.         }
  45.     }
  46. }
  47. unset($key);
  48. unset($key2);
  49. unset($value);
  50. unset($value2);
  51.  
  52. $input = "";
  53.  
  54. foreach ($inputArray as $value)
  55. {
  56.     $input = $input.$value;
  57.  
  58. }
  59. unset($value);
  60.  
  61. print_r($whitelistArray);
  62. echo "\n";
  63. echo $input;
  64.  
  65.  
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement