Location: PHPKode > projects > Todo Manager > todo/library/request.lib.php
<?php
require_once $_SERVER["DOCUMENT_ROOT"]."/".FOLDER."/library/util.lib.php";

/**
 * example:
 *
 * 		$params = request_getparams(array("age:int=45", "name=root", "gender:string", "password"));
 */
function request_getparams($params) {
	$ret = array();
	
	foreach($params as $key) {
		if (!preg_match_all("/(\w+)(\:(\w+))?(\=(.*))?/A", $key, $subpatterns))
			continue;
		$name = $subpatterns[1][0];
		$type = $subpatterns[3][0];
		$default = $subpatterns[5][0];
		
		$value = util_getfield($_REQUEST, $name);
		if (get_magic_quotes_gpc() && is_string($value))
			$value = stripslashes($value);
		if (!array_key_exists($name, $_REQUEST) && !util_empty($default))
			$value = $default;
		
		if (!util_empty($type)) {
			if (($type == "array") && util_empty($value))
				$value = array();
			else
				settype($value, $type);
		}
		
		$ret[$name] = $value;
	}
	
	return $ret;
}

/**
 * examples:
 *
 *		$age = request_get("age:int=45");
 *		$name = request_get("name=root");
 *		$gender = request_get("gender:string");
 *		$password = request_get("password");
 *
 */
function request_get($name) {
	if (!preg_match_all("/(\w+)(\:(\w+))?(\=(.*))?/A", $name, $subpatterns))
		continue;
	$name = $subpatterns[1][0];
	$type = $subpatterns[3][0];
	$default = $subpatterns[5][0];
	
	$value = util_getfield($_REQUEST, $name);
	if (get_magic_quotes_gpc() && is_string($value))
		$value = stripslashes($value);
	if (!array_key_exists($name, $_REQUEST) && !util_empty($default))
		$value = $default;
		
	if (!util_empty($type)) {
		if (($type == "array") && util_empty($value))
			$value = array();
		else
			settype($value, $type);
	}
	
	return $value;
}
?>
Return current item: Todo Manager