線上書籍

Home

XOOPS模組開發記錄

  1. $var :過濾變數
    $title:標題
    $required=true / 必填 false
    $type='string' / string (文字)、int(整數)、float(小數)、、
    $filter=
  2. moudles/ugm_tools2/ugmTools.php //檢查並傳回欲拿到資料使用的變數 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.