Format a phone number in PHP


/ Published in: PHP
Save to your folder(s)

Use this to format a phone number for display on a page.


Copy this code and paste it in your HTML
  1. function format_phnum($ac,$ph) {
  2. $areaCode = '(' . $ac . ') ';
  3. $npa = substr($ph,0,3) . '-';
  4. $num = substr($ph,3,4);
  5. return $areaCode . $npa . $num;
  6. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.