Home >php教程 >php手册 >如何封装get 方法和post 方法(附代码)

如何封装get 方法和post 方法(附代码)

PHPz
PHPzOriginal
2016-06-06 19:39:182052browse

引用了金老师代码,统一用g()方法来获取变量 function g($name, $defaultValue = "") {// php这里区分大小写,将两者都变为小写$_GET = array_change_key_case ( $_GET, CASE_LOWER );$name = strtolower ( $name );$v = isset ( $_GET [$name] ) ?              

function g($name, $defaultValue = "") {
	// php这里区分大小写,将两者都变为小写
	$_GET = array_change_key_case ( $_GET, CASE_LOWER );
	$name = strtolower ( $name );

	$v = isset ( $_GET [$name] ) ? $_GET [$name] : "";
	if ($v == "") 
        {
	    $_POST = array_change_key_case ( $_POST, CASE_LOWER );
	    $v = isset ( $_POST [$name] ) ?$_POST [$name] : "";
	}
            if ($v == "")
			return $defaultValue;
	    else
		{
			// 20141011 jc :  js_unescape($v)会引起 where ( col_subject like '%123%' ) 会变成 where ( col_subject like '%3%' )
			//$v =  js_unescape($v) ;
			$v = trim($v);
			return $v;
		}

	}

}

 【相关教程推荐】

1. php编程从入门到精通全套视频教程
2. php从入门到精通 
3. bootstrap教程

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more