. */ function sanitize($string, $allowed = '', $allow_aZ = true, $allow_09 = true) { /* * * Utility function for sanitize, check if a char is in a string. * Nested functions are unique to PHP, may look odd, but useful. */ function charin($c, $s) { $result = false; for ($i = 0; $i < strlen($s); $i++) { if ($c == $s[$i]) { $result = true; break; } // if } // for return $result; } // charin /* Check flags for a-Z and 0-9, on by default. */ if ($allow_aZ) $allowed .= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; if ($allow_09) $allowed .= '0123456789'; $result = ''; for ($i = 0; $i < strlen($string); $i++) { if (charin($string[$i], $allowed)) { $result .= $string[$i]; } // if } // for return $result; } // sanitize ?>