//檢查並傳回欲拿到資料使用的變數 if (!function_exists("filterVar")) { function filterVar($var,$title = '',$required=true,$type='string',$filter=""){ #---- 過濾資料 -------------------------- $myts = &MyTextSanitizer::getInstance(); #先判斷是否有填值 if($required == true and $var === ""){ redirect_header(XOOPS_URL, 3,"{$title}為必填!"); } if($type == "string"){ $var = $myts->addSlashes($var);//文字 }elseif($type == "int"){ $var = intval($var);//整數 }elseif($type == "float"){ $var = floatval($var);//小數 }else{ $var = $myts->addSlashes($var);//文字 } if ($filter) { $var = filter_var($var, $filter); if (!$var) { redirect_header(XOOPS_URL, 3,"不合法的{$title}"); } } return $var; } } ``` 3. 範例 4.