Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Print a phone number in format 333-333-4444 with PHP
<?php
$number = 1234567890;
// print out a phone number in format 123-456-7890
echo preg_replace('/\d{3}/', '$0-', str_replace('.', null, trim($number)), 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment