Last active
December 14, 2015 02:19
-
-
Save Stichoza/5013306 to your computer and use it in GitHub Desktop.
Parse POST/GET requests by one simple function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parse_request($vars, $encode_html = false, $return = false) { | |
$vars = explode(",", $vars); | |
if ($return) { | |
foreach ($vars as $value) { | |
$value = trim($value); // trim extra spaces | |
$result[$value] = get_var($value, $encode_html); | |
} | |
return $result; // returns associative array | |
} else { | |
foreach ($vars as $value) { | |
$value = trim($value); // trim extra spaces | |
global $$value; | |
$$value = get_var($value, $encode_html); // global scope variable | |
} | |
} | |
} | |
function get_var($var, $encode_html = false) { | |
if (!empty($_REQUEST[$var]) || $_REQUEST[$var] == 0) { | |
return ($encode_html) ? htmlspecialchars($_REQUEST[$var], ENT_QUOTES) : $_REQUEST[$var]; | |
} | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment