note 91239 modified in language.variables.variable by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Jun 2009 12:55:12 +0000 |
| Subject: | note 91239 modified in language.variables.variable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156219@lists.php.net to get a copy of this message | ||
Parsing and retrieving a value from superglobals, by a specified order, looping until it find one :
<?php
function GetInputString($name, $default_value = "", $format = "GPCS")
{
//order of retrieve default GPCS (get, post, cookie, session);
$format_defines = array (
'G'=>'_GET',
'P'=>'_POST',
'C'=>'_COOKIE',
'S'=>'_SESSION',
'R'=>'_REQUEST',
'F'=>'_FILES',
);
preg_match_all("/[G|P|C|S|R|F]/", $format, $matches); //splitting to globals order
foreach ($matches[0] as $k=>$glb)
{
if ( isset ($GLOBALS[$format_defines[$glb]][$name]))
{
return $GLOBALS[$format_defines[$glb]][$name];
}
}
return $default_value;
}
?>
--was--
Parsing and retrieving a value from superglobals, by a specified order, looping until it find one :
function GetInputString($name, $default_value = "", $format = "GPCS")
{
//order of retrieve default GPCS (get, post, cookie, session);
$format_defines = array (
'G'=>'_GET',
'P'=>'_POST',
'C'=>'_COOKIE',
'S'=>'_SESSION',
'R'=>'_REQUEST',
'F'=>'_FILES',
);
preg_match_all("/[G|P|C|S|R|F]/", $format, $matches); //splitting to globals order
foreach ($matches[0] as $k=>$glb)
{
if ( isset ($GLOBALS[$format_defines[$glb]][$name]))
{
return $GLOBALS[$format_defines[$glb]][$name];
}
}
return $default_value;
}
http://php.net/manual/en/language.variables.variable.php