【发布时间】:2012-06-19 14:09:42
【问题描述】:
需要从简历中提取电话号码。它可以以多种方式嵌入,可以在自己的行中:
714-555-1212
或排长队
1212 main st fullerton ca 92835 949.555.1212
想提取成数组——区号,3位,4位
这是我目前所拥有的,但是当同一线路上除了电话号码之外还有其他号码时,它不起作用:
function get_phone_number ($string){
$lines = explode("\n",trim($string));
foreach ($lines as $value){
//echo "Line: ".$value."<BR>";
preg_match_all('!\d+!', $value, $matches);
if (strlen($matches[0][0])=='3' && strlen($matches[0][1])=='3' && strlen($matches[0][2])=='4') {
$area_code = $matches[0][0];
}
}
return $area_code;
}
【问题讨论】:
-
然后呢?你想让我们为你写吗?
-
这不是 phpfreaks(您将有更好的机会为您编写代码)。至少先试试。
-
到目前为止我有这个,但是当同一行有其他数字时它不起作用,比如街道地址数字:
-
你只支持 NANP 格式的数字吗?