PHP input data Uniform class instance, PHP Unified class instance
This article describes the PHP input data unification class. Share to everyone for your reference. Specific as follows:
<?phpclass cls_request{private $getdata;//Store get Data private $postdata;//store post data private $requestdata;// Store data for request private $filedata;//Store file data private $cookiedata;//store Cooki static $_instance;//instance of this class private function __ Construct () {$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, return Cls_request object public static function Get_instance () {if (!) ( Self::$_instance instanceof self) {self::$_instance = new self ();} return self::$_instance; }//Gets the numeric variable passed over by the Get pass public function Get_num ($key) {if (!isset ($this->getdata[$key]) {return false;} return $this To_num ($this->getdata[$key]); }//Get post passed data variable public function Post_num ($key) {if (!isset ($this->postdata[$key]) {return false;} return $this-& Gt;to_num ($this->postdata[$key]); }//Get requestThe numeric variable passed over public function request_num ($key) {if (!isset ($this->requestdata[$key])) {return false;} return $this To_num ($this->requestdata[$key]); }//Gets the numeric variable passed by the cookie public function Cookie_num ($key) {if (!isset ($this->cookiedata[$key])) {return false;} return $ This->to_num ($this->cookiedata[$key]); }//Gets the value variable passed by file Public function Filedata ($key) {return $this->filedata[$key];//return Array}//Get get passed string variable public 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 passed by post to public function post_string ($key, $isfilter =true) {if (!isset ($this->postdata[$key])) {return False } if ($isfilter) {return $this->filter_string ($this->postdata[$key]);} else{return $this->postdata[$key];}} Gets the string variable passed by the request 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];}} Gets the string variable passed over by the cookie public function cookie_string ($key, $isfilter =true) {if (!isset ($this->cookiedata[$key])) { 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 the array Values are assigned to variables. Arrays for numeric indexes only, * default starting from 0 bits, *each () */while (list ($key, $value) = every ($data)) {//Not quite understood//handle data such as checkbox if (Is_array ($ Value) {$result [$key]= $value; }else{//General Data $result [$key] = Trim ($value); Remove whitespace and other predefined characters at both ends of the string}}}/conversion number Private Function To_num ($num) {if (Is_numeric ($num)) {return intval ($num),//convert variable to integer}els e{return false;}} Swap 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); Convert some of the predefined characters to HTML entities} return $data; }else{//Normal string return Htmlspecialchars ($data, ent_quotes);}}? >
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/959884.html www.bkjia.com true http://www.bkjia.com/PHPjc/959884.html techarticle PHP input Data Uniform class instance, PHP Unified Class Example This article describes the PHP input data uniform class. Share to everyone for your reference. Specific as follows: Phpclass cls_request{private $ ...