php 表单敏感字符过滤代码
-
-
-
- $_form = new formHtmlFind();
- class formHtmlFind{
-
-
-
-
-
-
- public function formHtml($array,$infoArray='')
- {
-
- if(emptyempty($array))return false;
- $newform = null;
-
- $this->infoArray = !emptyempty($infoArray)?$infoArray:array();
- $this->array['class'] = get_class_methods(get_class());
- foreach ($array as $key =>$arr)
- {
-
- $key = preg_replace("/[^a-z]/i",'',$key);
-
- $newform .= $this->outputForm($arr,$key);
- }
-
- return $newform.$this->jsError();
- }
-
-
-
- private function outputForm($arr,$key)
- {
- $value = null;
- if(emptyempty($arr))return false;
-
- $type = $key;
-
- $name = trim($arr[0]);
-
- $value = (!emptyempty($this->infoArray[$name]))? trim($this->infoArray[$name]):trim($arr[1]);
- $value = emptyempty($this->post[$name])? $value :trim($this->post[$name]);
-
- $title = trim($arr[2]);
-
- $style = trim($arr[3]);
- if($key!=="hidden")
- {
- $dt = "<dt>{$title}</dt><dd>";
-
- $dd = "<tt id="J{$name}"></tt></dd>rn";
- }
- return (!preg_match("/checkbox|select|radio/i",$key))?
- $dt.$this->newInput($type,$name,$value,$style,$title).$dd:
- $this->formSelect($type,$name,$arr[1],$title,$style);
- }
-
-
-
- public function postForm($array)
- {
-
- if(emptyempty($array)||emptyempty($_POST))return false;
- $this->post = $_POST;
- $this->array['class'] = get_class_methods(get_class());
- foreach ($array as $key =>$arr)
- {
-
- $key = preg_replace("/[^a-z]/i",'',$key);
-
- if (!emptyempty($arr)&&'file' != $key)$newData[trim($arr[0])] = $this->postFind($arr,$key);
- }
-
- if(!emptyempty($this->error))
- {
- return false;
- }
- else return $newData;
- }
-
-
-
- private function newInput($type,$name,$value,$style,$title)
- {
- switch ($type)
- {
- case 'text':
-
- return "<input type="text" name="{$name}" value="{$value}" {$style}/>";
- break;
- case 'password':
-
- return "<input type="password" name="{$name}" {$style}/>";
- break;
- case '':
-
- return "<textarea name="{$name}" {$style}/>{$value}</textarea>";
- break;
- case 'hidden':
-
- return "<input type="hidden" name="{$name}" value="{$value}" {$style}/>";
- break;
- case 'file':
-
- return "<input type= "file"name="{$name}" {$style}/>";
- break;
- case 'submit':
-
- return "<input type="submit" name="{$name}" value="$value" $style}/>";
- break;
- default:
- return "{$type}类型错误!!!";
- break;
- }
- }
-
-
-
-
- private function postFind($arr,$key)
- {
- if(emptyempty($arr))return false;
- $name = $title =$error =$find =$standard =null;
-
- $name = trim($arr[0]);
-
- $title = trim($arr[2]);
-
- $error = trim($arr[4]);
-
- $find = trim($arr[5]);
-
- $standard = trim($arr[6]);
-
- if(!emptyempty($standard))$this->error .=$this->ck_split($standard,$name,$title,$find,$error);
-
- if(is_array($this->post[$name]))$this->post[$name] = implode(",",$this->post[$name]);
-
- $KKarray = array();
- if(preg_match("/Y|N/is",$find))
- {
- $KKarray = split("_", $find);
-
- $escape_filter = (!emptyempty($KKarray[1]))?'ck_'.$KKarray[1]:'';
-
- $data = ($escape_filter)?$this->$escape_filter($this->post[$name]):$this->post[$name];
-
- }
- else $data = "";
-
- return $data;
- }
-
-
-
- private function formSelect($type,$name,$value,$title,$style)
- {
- $outform = null;
-
-  
|