PHP if.. elseif...else 问题
本帖最后由 xytianshiwx 于 2013-12-08 10:09:44 编辑
<?php
$field_func="COUNT|AVG|FIRST|LAST|MAX|MIN|SUM|TOP";
$where_field="Where|or|xor|and|in";
$param="name";
$sql_param_list=array();
if(false!==strpos($param,",")){//判断是否存在“,”
$sql_param_list["field"] = $param;
}else{
if(preg_match("/\b(".strtolower($field_func).")\b\((\*|[a-zA-Z_`])+\)/i", $param)){
$sql_param_list["field"] =$param;
}elseif(preg_match("/\b(".$where_field.")\b/i", $param)||preg_match("/(>|>|=)/i", $param)){//判断where
$sql_param_list["where"] =$param;
}elseif(preg_match("/\b(order|limit|group|)\b/i", $param,$param_name)){//判断order|limit|group
switch ($param_name[0]){
case "order" : $sql_param_list["order"] =$param;
break;
case "limit" : $sql_param_list["limit"] =$param;
break;
case "group" : $sql_param_list["group"] =$param;
break;
}
}else{
$sql_param_list["field"] =$param;
}
}
print_r($sql_param_list);
}elseif(preg_match("/\b(order
[解决办法]
limit
[解决办法]
group
[解决办法]
)\b/i", $param,$param_name)){//判断order
[解决办法]
limit
[解决办法]
group
==> "/\b(order
[解决办法]
limit
[解决办法]
group)\b/i", //正则多了个或