Reply to Re: parsing phone numbers

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация