0

Possible Duplicate:
Formatting Phone Numbers in PHP

cvs files from our clients contains phone numbers that are in this format

19995554444

but we must display them as

(999) 555-4444

on our website after retrieving them from our database ,so is there anyway to change its format using php? we cannot change the format inputted on our database, we can only change how it is displayed on out website.

any script will be ok as long as it is on php, we are using a mysql database to store data.

Community
  • 1
  • 1
telexper
  • 2,381
  • 8
  • 37
  • 66

1 Answers1

9

Here is a one way to do it.

$data = '+19995554444';

if(  preg_match( '/^\+\d(\d{3})(\d{3})(\d{4})$/', $data,  $matches ) )
{
    $result = '('. $matches[1] . ')' .$matches[2] . '-' . $matches[3];
    echo $result;
}

link & Possible duplicate of: Formatting Phone Numbers in PHP

Community
  • 1
  • 1
samayo
  • 16,163
  • 12
  • 91
  • 106