<?php function filter_($string, $type) { if(is_string($string)) { switch($type) { case 1: $type = FILTER_SANITIZE_URL; break; case 2: $type = FILTER_SANITIZE_FULL_SPECIAL_CHARS; break; case 3: $type = FILTER_SANITIZE_NUMBER_INT; break; default: throw new LogicException('type is not selected.'); break; } $string = stripslashes(trim($string)); return filter_var($string, $type); } } ?>
<?php $id = filter_($_GET['id'],3); $text = filter_($_POST['text'],2); $url = filter_($_GET['path'],1); $path = filter_($_SERVER['REQUEST_URI'],1); ?>