过滤脏字
/**
?* 過濾臟字
?* @array??? $gar
?* @string ? $gsr
?* @return? string
?*/
class checkKeys{
??????? public $arr;
??????? public $str;
??????? public function __construct($gar,$gsr){
??????????? $this->arr=$gar;
??????????? $this->str=$gsr;
??????????? $this->forKeys();
??????? }
??????? public function forKeys(){
??????????? $LEN=mb_strlen($this->str,'utf-8');#得到字符串長度
??????????? for($i=0;$i<$LEN;$i++){
??????????????? $JTR?? ?=mb_substr($this->str,$i,1,'utf-8');#得到當前循環字符
??????????????? if (in_array($JTR,array_keys($this->arr))){#如果拆分的字符在組織鍵值中
?? ??? ???? $NAR=$this->arrAddLen($this->arr[$JTR],$i);
?? ??? ???? if ($NAR){echo '有臟字';}
??????????????? }
??????????? }
??????? }
?? ?public function arrAddLen($snn,$sri){
?? ???? $restr=NULL;
?? ???? foreach ($snn as $sn){
?? ??? ?if ($sn==(mb_substr($this->str,$sri,mb_strlen($sn),'utf-8'))){
?? ??? ???? $restr=true;
?? ??? ???? break;
?? ??? ?}
?? ???? }
?? ???? return $restr;
?? ?}
?? ?public function __destruct(){
?? ???? $this->arr=NULL;
?? ???? $this->str=NULL;
?? ?}
??? }
??? 例
??? new checkKeys(array,string);
總結