Shay Hurley wrote:
this is probably a stupid question so apologies in advance.
I am trying to format a number to look like a phone number with "-"'s
between the numbers etc e.g. 15554256987 should be formatted as
1-555-425-6987.
What have you tried?
What did you expect and what did your script do?
Are you sure all your numbers have exactly 11 digits?
Here's a 'brute force' method to insert dashes at the positions you
specified. You might want to turn it into a function ... and change the
positions (and quantity) of dashes to insert.
#v+
<?php
$number = '15554256987';
$number = substr($number, 0, 1) . '-' . substr($number, 1);
// now $number = '1-5554256987';
$number = substr($number, 0, 5) . '-' . substr($number, 5);
// now $number = '1-555-4256987';
$number = substr($number, 0, 9) . '-' . substr($number, 9);
// now $number = '1-555-425-6987';
?>
#v-
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--