RE: [PHP] phone number formatting
| From: | Philip Olson | Date: | Thu, 02 Nov 2000 18:31:40 +0000 |
| Subject: | RE: [PHP] phone number formatting | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23438@lists.php.net to get a copy of this message | ||
np. although your route imho is harder :-) what is so difficult with
doing this :
print PhoneNumberFormat($value);
? or are you trying to do something other then output the entire number
of 1112224444 to (111) 222-4444 ? also, if you are going to use this
format all the time then you should enter it as such into the db :
$value = PhoneNumberFormat($value);
then insert $value into db upon submission. this will basically strip
whatever the user inputs i.e. :
111-222-4444
111 222 4444
(111)2224444
etc. and input it in your desired format. this is ideal as it means
running it once vs. everytime the page is viewed - and your data will look
all pretty and nice and similar. this is suggested. although it does not
take into account :
1-111-222-4444
hmm. this could get a little more complicated :-) i'll let you know what
i come up with (ya, famous last words) although i still am unsure how to
go about global numbers with country codes ... anyone know of an array or
something with all country codes? hmm, this could be fun.
ttyl,
philip
--
be outside the box.
On Thu, 2 Nov 2000, Jerry Lake wrote:
> Thanks for the help, I appreciate it
> I chose and easier route, however I
> just store the area code in a separate field
> and add the "(" around it
>
> J. Lake
>
> -----Original Message-----
> From: Philip Olson [mailto:philip@theprojects.org]
> Sent: Wednesday, November 01, 2000 5:46 PM
> To: Jerry Lake
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] phone number formatting
>
>
> Hi Jerry-
>
> I am learning regular expressions so will tackle this one, keep in mind I
> am learning. I use PRCE because that is what I am learning :-)
>
> Created a little function here, you can snip whatever out of course but
> wanted to add a little sanity checking, it can use more in future as to
> take in account non-US folk but anyway here goes :
>
Err, them are bad comments hehe sorry :-) //po
> <?php
> // Purpose : Convert 0123456789 into (012) 345-6789
> // Use : $value = '4115551212';
> // print PhoneNumberFormat($value);
>
> function PhoneNumberFormat ($value) {
>
> // replace non-numbers with nothing (strip them) jic
> $value = preg_replace('/[^0-9]/','',$value);
>
> // get length of value
> $valuelength = strlen($value);
>
> if ($valuelength == '10')
> {
> $value = preg_replace('/^(\d{3})(\d{3})(\d{4})/','(\\1)
> \\2-\\3',$value);
> Return $value; // like this (411) 555-1212
> }
> else
> {
> Return $value; // If not 10 then return it
> // Or return something else I suppose
> }
>
> }
>
> ?>
>
> The key to the output is : '(\\1) \\2-\\3' it should look familiar to the
> actual output right? The ( ) and - are in there.
>
> This is a good start and does what you need. It might be fun to add
> checks for other phone numbers but I am not at all familiar with global
> phone number schemes - all thoughts welcome as I desire to have global
> phone number check (we are part of global economy now !!!)
>
> Regards,
>
> Philip
>
> --
> be outside the box.
>
> On Wed, 1 Nov 2000, Jerry Lake wrote:
>
> > If I have phone numbers stored in my database
> > as "1234567890" when I call them out to a page
> > how can I display them as "(123) 456-7890"
> > some sort of ereg_replace(); I'm guessing, but not sure how to structure.
> > any help is appreciated
> > Regards,
> >
> > J.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>