php輸入數(shù)據(jù)統(tǒng)一類實(shí)例__第1頁(yè)
php輸入數(shù)據(jù)統(tǒng)一類實(shí)例__第2頁(yè)
php輸入數(shù)據(jù)統(tǒng)一類實(shí)例__第3頁(yè)
php輸入數(shù)據(jù)統(tǒng)一類實(shí)例__第4頁(yè)
php輸入數(shù)據(jù)統(tǒng)一類實(shí)例__第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余3頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、php輸入數(shù)據(jù)統(tǒng)一類實(shí)例_ 這篇文章主要介紹了php輸入數(shù)據(jù)統(tǒng)一類,實(shí)例分析了針對(duì)輸入數(shù)據(jù)的各種轉(zhuǎn)換技巧,具有肯定參考借鑒價(jià)值,需要的伴侶可以參考下 本文實(shí)例講解并描述了php輸入數(shù)據(jù)統(tǒng)一類。分享給大家供大家參考。具體如下: ?php class cls_request private $getdata;/存儲(chǔ)get的數(shù)據(jù) private $postdata;/存儲(chǔ)post的數(shù)據(jù) private $requestdata;/存儲(chǔ)request的數(shù)據(jù) private $filedata;/存儲(chǔ)file的數(shù)據(jù) private $cookiedata;/存儲(chǔ)cooki static $_instan

2、ce;/本類的實(shí)例 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); /類的初始化,返回cls_request對(duì)象

3、 public static function get_instance() if(!(self:$_instance instanceof self) self:$_instance = new self(); return self:$_instance; /獵取GET傳遞過(guò)來(lái)的數(shù)值變量 public function get_num($key) if(!isset($this-getdata$key) return false; return $this-to_num($this-getdata$key); /獵取POST傳遞過(guò)來(lái)的數(shù)據(jù)變量 public function post_nu

4、m($key) if(!isset($this-postdata$key) return false; return $this-to_num($this-postdata$key); /獵取Request傳遞過(guò)來(lái)的數(shù)值變量 public function request_num($key) if(!isset($this-requestdata$key) return false; return $this-to_num($this-requestdata$key); /獵取Cookie傳遞過(guò)來(lái)的數(shù)值變量 public function cookie_num($key) if(!isset(

5、$this-cookiedata$key) return false; return $this-to_num($this-cookiedata$key); /獵取File傳遞過(guò)來(lái)的數(shù)值變量 public function filedata($key) return $this-filedata$key;/返回?cái)?shù)組 /獵取GET傳遞過(guò)來(lái)的字符串變量 public function get_string($key,$isfilter=true) if(!isset($this-getdata$key) return false; if($isfilter) return $this-filter

6、_string($this-getdata$key); else return $this-getdata$key; /獵取POST傳遞過(guò)來(lái)的字符串變量 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; /獵取Request傳遞過(guò)來(lái)的字符串變量 public function

7、 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; /獵取Cookie傳遞過(guò)來(lái)的字符串變量 public function cookie_string($key,$isfilter=true) if(!isset($this-cookiedata$key) return false;

8、 if($isfilter) return $this-filter_string($this-cookiedata$key); else return $this-cookiedata$key; /格式化數(shù)據(jù) private function format_data($data) $result = array(); if(!is_array($data) $data = array(); /* *list()表示用數(shù)組的數(shù)值給變量賦值。只用于數(shù)字索引的數(shù)組, *默認(rèn)從0位開頭,按挨次下去 *each() */ while(list($key,$value) = each($data)/不太

9、明白 /處理checkbox之類的數(shù)據(jù) if(is_array($value) $result$key=$value; else/一般數(shù)據(jù) $result$key = trim($value); /刪除字符串兩端空白及其它預(yù)定義字符 /轉(zhuǎn)化數(shù)字 private function to_num($num) if(is_numeric($num) return intval($num);/將變量轉(zhuǎn)為整數(shù) else return false; /過(guò)換過(guò)濾字符串 private function filter_string($data) if($data=null) return false; if(is_array($data) foreach($data as $k=$v) $data$k = htmlspecialchars

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論