This example describes the unified PHP input data class. Share to everyone for your reference. as follows:
<?php class cls_request{Private $getdata//Store get Data private $postdata;//store post data private $requestdata;//Store Request Data private $filedata//stores file's data private $cookiedata;//Storage Cooki static $_instance;//instance Private function of this class __constru
CT () {$this->getdata = Self::format_data ($_get);
$this->postdata = Self::format_data ($_post);
$this->requestdata = Array_merge ($this->getdata, $this->postdata);
$this->cookiedata = Self::format_data ($_cookie);
$this->filedata = Self::format_data ($_files); ///class initialization, returns the Cls_request object public static function Get_instance () {if (!
Self::$_instance instanceof Self)) {self::$_instance = new self ();
return self::$_instance;
//Gets the numeric variable public function Get_num ($key) {if (!isset ($this->getdata[$key)) that the get passed over {return false;
return $this->to_num ($this->getdata[$key]);
//Gets the data variable public function Post_num ($key) {if (!isset ($this->postdata[$key)) that the post passed over {return false; return $this->to_num ($this->postdata[$key]);
//Gets the numeric variable public function Request_num ($key) {if (!isset ($this->requestdata[$key)) that the request passes over {return false;
return $this->to_num ($this->requestdata[$key]);
The numeric variable public function Cookie_num ($key) {if (!isset ($this->cookiedata[$key)) that the cookie passed over is {return false;
return $this->to_num ($this->cookiedata[$key]); //Gets the numeric variable public function filedata ($key) {return $this->filedata[$key];//returns the array}//Gets the string variable passed by the file Publi
C function get_string ($key, $isfilter =true) {if (!isset ($this->getdata[$key])) {return false;
} if ($isfilter) {return $this->filter_string ($this->getdata[$key]);
}else{return $this->getdata[$key]; }//Gets the string variable public function post_string ($key, $isfilter =true) {if (!isset ($this->postdata[$key)) that was passed over by post. {Retur
n false;
} if ($isfilter) {return $this->filter_string ($this->postdata[$key]);
}else{return $this->postdata[$key]; I//Get the string variable that the request passes over PUBlic function request_string ($key, $isfilter =true) {if (!isset ($this->requestdata[$key])) {return false;
} if ($isfilter) {return $this->filter_string ($this->requestdata[$key]);
}else{return $this->requestdata[$key];
}//Get the string variable public function cookie_string ($key, $isfilter =true) {if (!isset ($this->cookiedata[$key)) passed by the cookie {
return false;
} if ($isfilter) {return $this->filter_string ($this->cookiedata[$key]);
}else{return $this->cookiedata[$key];
}///Format Data Private Function Format_data ($data) {$result = array ();
if (!is_array ($data)) {$data = array (); /* *list () indicates that the value of the array is assigned to the variable. Arrays that are used only for numeric indices, * The default starts with 0-bit, in order *each ()/while (list ($key, $value) = each ($data)) {//Do not understand//deal with the data such as a checkbox (Is_array (
$value)) {$result [$key]= $value;
}else{//General Data $result [$key] = Trim ($value); Delete string ends and other predefined characters}}//Convert digital Private Function To_num ($num) {if (Is_numeric ($num)) {return intval ($num);
Integer}else{return false;}//Over filter string private function filter_string ($data) {if ($data ===null) {return false;
} if (Is_array ($data)) {foreach ($data as $k => $v) {$data [$k] = Htmlspecialchars ($v, ent_quotes);
Converts some predefined characters into HTML entities} return $data;
}else{//Ordinary string return Htmlspecialchars ($data, ent_quotes); }}}?>
I hope this article will help you with your PHP programming.