/**
* 获取输入数据
* @param string $key 获取的变量名
* @param mixed $default 默认值
* @param string $function 处理函数
* @return mixed
*/
function input($key = '', $default = '', $function = '')
{
if ($pos = strpos($key, '.')) {
list($method, $key) = explode('.', $key, 2);
if ( ! in_array($method, array('get', 'post', 'request'))) {
$key = $method.'.'.$key;
$method = 'param';
}
} else {
$method = 'param';
}
$method = strtolower($method);
if ($method == 'get') {
return empty($key) ? $_GET : (isset($_GET[$key]) ? ($function ? $function($_GET[$key]) : $_GET[$key]) : $default);
} elseif ($method == 'post') {
if (empty($_POST)) {
$_POST = file_get_contents('php://input');
if (strpos($_POST, '=')) {
$_POST = parse_str($_POST, $data);
$_POST = $data;
} else {
$_POST = json_decode(file_get_contents('php://input'), true);
}
}
return empty($key) ? $_POST : (isset($_POST[$key]) ? ($function ? $function($_POST[$key]) : $_POST[$key]) : $default);
} elseif ($method == 'request') {
return empty($key) ? $_REQUEST : (isset($_REQUEST[$key]) ? ($function ? $function($_REQUEST[$key]) : $_REQUEST[$key]) : $default);
} elseif ($method == 'param') {
$param = array_merge($_GET, is_array($_POST) ? $_POST : array(), $_REQUEST);
return empty($key) ? $param : (isset($param[$key]) ? ($function ? $function($param[$key]) : $param[$key]) : $default);
} else {
return false;
}
}

© 版权声明
文章未经允许请勿转载。
THE END
暂无评论内容