I am trying to figure out how to take the output of a row for telephone numbers like this: <td width="81%"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"> <? echo $row['phone'] ?>
Which would display 5555551212
and format it so that it contains parens and a dash like so: (555)555-1212
I'm kind of new to PHP but couldn't you use the string EXPLODE function to break it up into a 3 bucket array and then format it that way?
$var='5555551212'; $var = "(".substr($var,0,3).")".substr($var,3,3)."-".substr($var,6); echo $var ."<BR>";
There may be a shorter way but you can do this:
$wholenum = ($row['phone'?)
$areacode = substr($wholenum, 0,3); $first3 = substr{$wholenum, 3,3); $last4 = substr($wholenum, -4,);
$phoneformated = "(" . $areacode . ") " . $first3 . " - " . $last4);
first line should be $wholenum = $row['phone']; <- what's the question mark in your version for. If it's something I don't know about, just throw it in there. What does it do though?
The rest of the code should work fine though.
And the winner is... Ben More concise and tidy.