Forum Moderators: coopster
I already check the input to make sure it is 10 digits long and all integers.
function getPhoneNumber($someValue)
{
$phoneNumber = "$someValue";
$i = 0;
while ( $i < 10)
{
if ($i == 3 ¦¦ $i == 6)
$totalNumber .= "-";
$totalNumber .= $phoneNumber{$i};
$i++;
}
return $totalNumber;
}//end getPhoneNumber
function string_format($format, $string, $placeHolder = "#")
{
$numMatches = preg_match_all("/($placeHolder+)/", $format, $matches);
foreach ($matches[0] as $match)
{
$matchLen = strlen($match);
$format = preg_replace("/$placeHolder+/", substr($string, 0, $matchLen), $format, 1);
$string = substr($string, $matchLen);
}
return $format;
}To Use:
print string_format("(###)###-####", "4015551212");
will print out:
(401)555-1212
Hope it's of some use to you
Michal Cibor