RE: [PHP] Formatting phone numbers?

2004-04-17 Thread Andy Crain
Jay,

> Here is a little more of the larger function with comments (more
> comments than code, which is never a Bad Thing [tm]). I am only showing
> the handling for two basic types of telephone numbers with explanation
> for additional verification which we would typically use, since we have
> those resources available.

Great. Thanks very much.
Andy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Formatting phone numbers?

2004-04-16 Thread Jay Blanchard
[snip]
> [stuff you may not need]
> This is a boiled down version of a longer function that counts string
> lengths to determine how many dashes might need to be added. Let's say
> you have the area code in the number, like 2108765432. Being a ten
digit
> number with a recognizable area code we can then add a portion to the
> function to add the two needed dashes, making the number more
readable.
> [/stuff]

I'd love to see that larger function, if you care to share.
[/snip]

Here is a little more of the larger function with comments (more
comments than code, which is never a Bad Thing [tm]). I am only showing
the handling for two basic types of telephone numbers with explanation
for additional verification which we would typically use, since we have
those resources available.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Formatting phone numbers?

2004-04-16 Thread Andy Crain
Good stuff.

> [stuff you may not need]
> This is a boiled down version of a longer function that counts string
> lengths to determine how many dashes might need to be added. Let's say
> you have the area code in the number, like 2108765432. Being a ten digit
> number with a recognizable area code we can then add a portion to the
> function to add the two needed dashes, making the number more readable.
> [/stuff]

I'd love to see that larger function, if you care to share.
Andy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Formatting phone numbers?

2004-04-16 Thread Paul Fine
Thanks!



-Original Message-
From: Jay Blanchard [mailto:[EMAIL PROTECTED] 
Sent: April 16, 2004 7:33 AM
To: BOOT; [EMAIL PROTECTED]
Subject: RE: [PHP] Formatting phone numbers?

[snip]
Thanks for any help, even if you just suggest built in functions to look
at.

I'm looking for a way to take a 7 digit number and put it into xxx-
format.

So basically the logic is to count 3 characters into $number and insert
a
"-" there.
[/snip]

As a telecom we use several methods, but here is a small function which
allows us to keep both formats where needed

function addTNDashes ($oldNumber){
   $newNumber = substr($oldNumber, 0, 3) . "-" . substr($oldNumber, 3,
4);
   
   return $newNumber;
}

$telephone = "8654321";
$newTele = addTNDashes($telephone);
echo $newTele;

output is 865-4321 and we can still use $telephone if we need to. 
[stuff you may not need]
This is a boiled down version of a longer function that counts string
lengths to determine how many dashes might need to be added. Let's say
you have the area code in the number, like 2108765432. Being a ten digit
number with a recognizable area code we can then add a portion to the
function to add the two needed dashes, making the number more readable.
[/stuff]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Formatting phone numbers?

2004-04-16 Thread Rob Ellis
On Thu, Apr 15, 2004 at 06:11:57PM -0400, John W. Holmes wrote:
> Rob Ellis wrote:
> >On Thu, Apr 15, 2004 at 04:31:09PM -0500, BOOT wrote:
> >>
> >>I'm looking for a way to take a 7 digit number and put it into xxx-
> >>format.
> >>
> >>So basically the logic is to count 3 characters into $number and insert a
> >>"-" there.
> >
> >substr_replace($string, '-', 3, 0);
> 
> Won't that replace the number, though, not insert the dash?

No, it does the right thing. The last 0 is the number of 
characters to replace.

- Rob

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Formatting phone numbers?

2004-04-16 Thread Jay Blanchard
[snip]
Thanks for any help, even if you just suggest built in functions to look
at.

I'm looking for a way to take a 7 digit number and put it into xxx-
format.

So basically the logic is to count 3 characters into $number and insert
a
"-" there.
[/snip]

As a telecom we use several methods, but here is a small function which
allows us to keep both formats where needed

function addTNDashes ($oldNumber){
   $newNumber = substr($oldNumber, 0, 3) . "-" . substr($oldNumber, 3,
4);
   
   return $newNumber;
}

$telephone = "8654321";
$newTele = addTNDashes($telephone);
echo $newTele;

output is 865-4321 and we can still use $telephone if we need to. 
[stuff you may not need]
This is a boiled down version of a longer function that counts string
lengths to determine how many dashes might need to be added. Let's say
you have the area code in the number, like 2108765432. Being a ten digit
number with a recognizable area code we can then add a portion to the
function to add the two needed dashes, making the number more readable.
[/stuff]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Formatting phone numbers?

2004-04-15 Thread John W. Holmes
Rob Ellis wrote:
On Thu, Apr 15, 2004 at 04:31:09PM -0500, BOOT wrote:
>>
I'm looking for a way to take a 7 digit number and put it into xxx-
format.
So basically the logic is to count 3 characters into $number and insert a
"-" there.
substr_replace($string, '-', 3, 0);
Won't that replace the number, though, not insert the dash?

$formatted_number = preg_replace('/^([0-9]{3})/,'\1-',$number);

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Formatting phone numbers?

2004-04-15 Thread Rob Ellis
On Thu, Apr 15, 2004 at 04:31:09PM -0500, BOOT wrote:
> Thanks for any help, even if you just suggest built in functions to look at.
> 
> I'm looking for a way to take a 7 digit number and put it into xxx-
> format.
> 
> So basically the logic is to count 3 characters into $number and insert a
> "-" there.

substr_replace($string, '-', 3, 0);

- Rob

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Formatting phone numbers

2002-06-23 Thread Chris Shiflett

Corinne Shea wrote:

>Hi,
>
>I'd like to write a function that will take a string of characters and 
>output it in a phone number format (xxx)xxx- and one for credit 
>cards ---.
>
This is actually very easy to do if all you want to do is format, 
meaning you have already validated the data and can be assured that you 
have ten digits (or 16 for credit cards).

$phone_num="8005551212";
$formatted_phone_num="(" . substr($phone_num, "0", "3") . ") " . 
substr($phone_num, "3", "3") . "-" . substr($phone_num, "6", "4");

I'm sure there are other ways to achieve the same result, but you 
basically want to look at string functions that allow you to slice a 
phone number into whatever parts you want (area code, prefix, suffice 
for US numbers) and then create a string formatted however you want.

Chris


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Formatting phone numbers

2002-06-23 Thread Paul Roberts

preg_replace will do it.

$returnValue = preg_replace("/(\d{3})(\d{3})(\d{4})/","($1)$2-$3",$returnValue);

(\d{3})(\d{3})(\d{4}) = $0 or \\0 we aren't using this match

we are using the subpatterns in brackets
(\d{3}) =$1 or \\1 matches 3 numbers
(\d{3}) =$2 or \\2 matches 3 numbers
(\d{4}) =$3 or \\3 matches 4 numbers

which we use to make the replacement
($1)$2-$3

http://za2.php.net/manual/en/function.preg-replace.php

so that's the phone number, I'll leave the cc to you.

Paul Roberts
[EMAIL PROTECTED]


 


Phone Number: 


- Original Message - 
From: "Corinne Shea" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, June 23, 2002 8:06 PM
Subject: [PHP] Formatting phone numbers


Hi,

I'd like to write a function that will take a string of characters and 
output it in a phone number format (xxx)xxx- and one for credit 
cards ---. What I have below will currently remove 
non-numeric characters from the string, but I'm not sure how to do the 
rest of the formatting. Any help would be appreciated.

By the way, any recommendations for good php tutorials for beginners?

Thanks,
Corinne








 


Phone Number: 





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php