给朋友做的一个小系统中用到的,当时想了好半天才想出的一个方法。
主要功能是自动识别出话单中需要的信息。
这里记录一下以备不时之需,不过现在看看当时自己写的这两个函数都有点晕晕的感觉了。
function goodcheck($arr)
{
$arr = array_count_values($arr);
$maxval = array_search(max($arr), $arr);
return $maxval;
}
function autocheck($arr)
{
$a=array();$b=array();$c=array();$d=array();$e=array();
$local = array("start" => $a,"address" => $b,"times" =>$c,"phone" =>$d,"type" =>$e);
$new = array("start" => "","address" => "","times" =>"","phone" =>"","type" =>"");
for($i=1;$i < 10;$i++)
{
if($arr[$i]!="")
{
foreach ($arr[$i] as $key => $val)
{
$n = sizeof($arr[$i]);
if($n < 4)continue;
if(strstr("主叫",$val) != NULL || strstr("被叫",$val) != NULL){$local['type'][]=$key;}
if(preg_match("/(\-|\/)/",$val)){$local['start'][]=$key;}
if((!strstr($val, "-") && !strstr($val, "/") && strstr($val, ":") && preg_match("/[0-9]+/",$val)) || (checkNum($val) && strlen($val) < 3) && ($val > 0)){$local['times'][]=$key;}
if(strstr("上海",$val) != NULL){$local['address'][]=$key;}
if(checkNum($val) && strlen($val) >= 8){$local['phone'][]=$key;}
}
}
}
$new['type'] = goodcheck($local['type']);
$new['address'] = goodcheck($local['address']);
$new['phone'] = goodcheck($local['phone']);
$new['start']=goodcheck($local['start']);
$new['times']=goodcheck($local['times']);
return $new;
}
雨田博客