need to extract phone number from resume. it can be embedded in a variety of ways, can be in its own line:
714-555-1212
or in a long line
1212 main st fullerton ca 92835 949.555.1212
would like to extract it into array - area code, 3 digits, 4 digits
this is what i have so far, but it doesnt work when there are other numbers on same line besides phone number:
function get_phone_number ($string){
$lines = explode("
",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;
}
<?php
$areaCodes = array();
$threeDigits = array();
$fourDigits = array();
preg_match_all('/(\d{3})-(\d{3})-(\d{4})/',$content,$matches);
if(count($matches[1])>0)
{
for($i=0; $i<count($matches[1]); $i++)
{
array_push($areaCodes,$matches[1][$i]);
array_push($threeDigits,$matches[2][$i]);
array_push($fourDigits,$matches[3][$i]);
}
}
preg_match_all('/\((\d{3})\)-(\d{3})-(\d{4})/',$content,$matches);
if(count($matches[1])>0)
{
for($i=0; $i<count($matches[1]); $i++)
{
array_push($areaCodes,$matches[1][$i]);
array_push($threeDigits,$matches[2][$i]);
array_push($fourDigits,$matches[3][$i]);
}
}
preg_match_all('/(\d{3}).(\d{3}).(\d{4})/',$content,$matches);
if(count($matches[1])>0)
{
for($i=0; $i<count($matches[1]); $i++)
{
array_push($areaCodes,$matches[1][$i]);
array_push($threeDigits,$matches[2][$i]);
array_push($fourDigits,$matches[3][$i]);
}
}
preg_match_all('\((\d{3})\).(\d{3}).(\d{4})/',$content,$matches);
if(count($matches[1])>0)
{
for($i=0; $i<count($matches[1]); $i++)
{
array_push($areaCodes,$matches[1][$i]);
array_push($threeDigits,$matches[2][$i]);
array_push($fourDigits,$matches[3][$i]);
}
}
print_r($areaCodes);
print_r($threeDigits);
print_r($fourDigits);