|
Posted by Roy Kaldung on 05/07/07 21:04
laredotornado@zipmail.com schrieb:
> Hi,
>
> Using php 4.4.4, I am looking to parse a US phone number string into 3
> smaller strings -- area code, the first part of the phone number (3
> digits) and the last part of the phone number (4 digits). The only
> given is that there will be 10 digits in the string, but people may
> include spaces, parens, or other characters. These are all strings
> I'd expect
>
> $p = "5558675309";
> $p = "(312) 123-4567";
> $p = "512-234-5678";
>
> Thanks for any code snippets, - Dave
>
<?php
$a = "(312) 123-4567";
$input = str_replace(array(' ','-',')','('), '', $a);
if (preg_match('/(\d{3})(\d{3})(\d{4})/', $input, $output)) {
var_dump($output);
} else {
print "wrong format!";
}
?>
hth,
Roy
[Back to original message]
|