Php unified input data Class instance, php unified class instance _ PHP Tutorial

Source: Internet
Author: User
Php unified input data Class instances, php unified class instances. Php unified input data Class instance, php unified class instance this article describes the php unified input data class. Share it with you for your reference. Details: phpclasscls_request {private $ php unified input data Class instance, php unified class instance

This example describes the unified class of php input data. Share it with you for your reference. The details are as follows:

<? Phpclass cls_request {private $ getdata; // stores get data private $ postdata; // stores post data private $ requestdata; // Stores request data private $ filedata; // store the file data private $ cookiedata; // store cooki static $ _ instance; // This class of instance private function _ construct () {$ this-> getdata = self: format_data ($ _ GET); $ this-> postdata = self: format_data ($ _ POST ); $ this-> requestdata = array_merge ($ this-> getdata, $ this-> postdata); $ this-> cookie Data = 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 ;} // Obtain the public function get_num ($ key) {if (! Isset ($ this-> getdata [$ key]) {return false;} return $ this-> to_num ($ this-> getdata [$ key]);} // Obtain the public function post_num ($ key) {if (! Isset ($ this-> postdata [$ key]) {return false;} return $ this-> to_num ($ this-> postdata [$ key]);} // Obtain the public function request_num ($ key) {if (! Isset ($ this-> requestdata [$ key]) {return false;} return $ this-> to_num ($ this-> requestdata [$ key]);} // Obtain the public function cookie_num ($ key) {if (! Isset ($ this-> cookiedata [$ key]) {return false;} return $ this-> to_num ($ this-> cookiedata [$ key]);} // Obtain the public function filedata ($ key) {return $ this-> filedata [$ key]; // return Array} // GET the public function get_string ($ key, $ isfilter = true) passed by GET {if (! Isset ($ this-> getdata [$ key]) {return false;} if ($ isfilter) {return $ this-> filter_string ($ this-> getdata [$ key]);} else {return $ this-> getdata [$ key];} // Obtain the POST-passed string variable 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];} // Obtain the public function request_string ($ key, $ isfilter = true) passed by the Request {if (! Isset ($ this-> requestdata [$ key]) {return false;} if ($ isfilter) {return $ this-> filter_string ($ this-> requestdata [$ key]);} else {return $ this-> requestdata [$ key];} // Obtain the public function cookie_string ($ key, $ isfilter = true) passed by the Cookie {if (! Isset ($ this-> cookiedata [$ key]) {return false;} if ($ isfilter) {return $ this-> filter_string ($ this-> cookiedata [$ key]);} else {return $ this-> cookiedata [$ key];} // format the data private function format_data ($ data) {$ result = array (); if (! Is_array ($ data) {$ data = array ();}/** list () indicates that the variable is assigned a value using the array value. Used only for numeric index arrays. * The default value starts from 0 and goes down in order. * each () */while (list ($ key, $ value) = each ($ data )) {// Not clear // process data such as checkbox if (is_array ($ value) {$ result [$ key] = $ value ;} else {// normal data $ result [$ key] = trim ($ value ); // delete the white space at both ends of the string and other pre-defined characters }}// convert the number private function to_num ($ num) {if (is_numeric ($ num )) {return intval ($ num); // Convert the variable to an integer} else {return false ;}// filter the string private function filter_string ($ data) {if ($ data = null) {retu Rn false;} if (is_array ($ data) {foreach ($ data as $ k => $ v) {$ data [$ k] = htmlspecialchars ($ v, ENT_QUOTES); // Convert some predefined characters into html entities} return $ data;} else {// normal string return htmlspecialchars ($ data, ENT_QUOTES) ;}}?>

I hope this article will help you with php programming.

Examples in this article describe the unified class of php input data. Share it with you for your reference. Details: phpclass cls_request {private $...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.