Skip to main content

Format Types

The PhoneNumberFormat enum defines four standard ways to format phone numbers. Each format serves a specific purpose and use case.
enum PhoneNumberFormat: int
{
    case E164 = 0;
    case INTERNATIONAL = 1;
    case NATIONAL = 2;
    case RFC3966 = 3;
}

E164 Format

The E.164 format is the international standard for phone number formatting. It’s compact, machine-readable, and ideal for storage.

Characteristics

  • Starts with a + symbol
  • Contains only digits (no spaces, dashes, or parentheses)
  • Maximum length of 15 digits (excluding the +)
  • Includes country code
  • No formatting applied

Example

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$number = $phoneUtil->parse('0117 496 0123', 'GB');

echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::E164);
// Output: +441174960123
$ukNumber = $phoneUtil->parse('0117 496 0123', 'GB');
echo $phoneUtil->format($ukNumber, \libphonenumber\PhoneNumberFormat::E164);
// Output: +441174960123

When to Use E164

E.164 is ideal for storing phone numbers in databases:
  • Consistent format across all numbers
  • No ambiguity about country or region
  • Easy to index and search
  • No formatting characters to strip
// Store in database
$e164 = $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::E164);
$db->insert('users', ['phone' => $e164]);
Many APIs require or prefer E.164 format:
  • SMS gateways (Twilio, MessageBird, etc.)
  • Voice calling services
  • Authentication services
  • CRM systems
// Send to API
$apiClient->sendSMS([
    'to' => $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::E164),
    'message' => 'Your code is 123456'
]);
E.164 makes it easy to detect duplicate numbers:
$num1 = $phoneUtil->parse('(650) 253-0000', 'US');
$num2 = $phoneUtil->parse('650-253-0000', 'US');

$e164_1 = $phoneUtil->format($num1, \libphonenumber\PhoneNumberFormat::E164);
$e164_2 = $phoneUtil->format($num2, \libphonenumber\PhoneNumberFormat::E164);

if ($e164_1 === $e164_2) {
    echo "Same number!"; // This will match
}

INTERNATIONAL Format

The INTERNATIONAL format is human-readable and follows ITU-T Recommendation E.123 for international display.

Characteristics

  • Starts with a + symbol
  • Includes country code
  • Contains spaces for readability
  • Consistent across all regions
  • Suitable for display

Example

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$number = $phoneUtil->parse('0117 496 0123', 'GB');

echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
// Output: +44 117 496 0123
// UK
$uk = $phoneUtil->parse('0117 496 0123', 'GB');
echo $phoneUtil->format($uk, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
// Output: +44 117 496 0123

// US
$us = $phoneUtil->parse('(650) 253-0000', 'US');
echo $phoneUtil->format($us, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
// Output: +1 650-253-0000

// Japan
$jp = $phoneUtil->parse('03-1234-5678', 'JP');
echo $phoneUtil->format($jp, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
// Output: +81 3-1234-5678

When to Use INTERNATIONAL

Use INTERNATIONAL format when displaying numbers to users, especially in international contexts.
  • User interfaces - Easy to read and recognizable
  • Contact lists - Clear country identification
  • Email signatures - Professional appearance
  • Printed materials - Business cards, letterheads
  • International correspondence - Clear for any recipient
// Display in UI
echo "<p>Contact us at: " . 
     $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::INTERNATIONAL) . 
     "</p>";

NATIONAL Format

The NATIONAL format displays numbers as they would be dialed within their home country.

Characteristics

  • No country code
  • Includes national prefix (e.g., “0” in UK)
  • Region-specific formatting
  • Only valid within the same country
  • Most natural for local users

Example

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$number = $phoneUtil->parse('+44 117 496 0123', null);

echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::NATIONAL);
// Output: 0117 496 0123
$ukNumber = $phoneUtil->parse('+44 117 496 0123', null);
echo $phoneUtil->format($ukNumber, \libphonenumber\PhoneNumberFormat::NATIONAL);
// Output: 0117 496 0123
// Includes leading "0" (national prefix)

When to Use NATIONAL

Only use NATIONAL format when you’re certain users are in the same country as the phone number. For international applications, prefer INTERNATIONAL format.
  • Domestic applications - Apps serving one country only
  • Local business listings - When all users are local
  • Print ads - For local newspapers/magazines
  • Caller ID display - When showing local calls
// Show national format for same-country users
$userCountry = 'GB';
$numberCountry = $phoneUtil->getRegionCodeForNumber($number);

if ($userCountry === $numberCountry) {
    echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::NATIONAL);
} else {
    echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
}

RFC3966 Format

The RFC3966 format is designed for tel: URI scheme, used in clickable phone links.

Characteristics

  • Starts with tel: prefix
  • Uses hyphens instead of spaces
  • Based on INTERNATIONAL format
  • Extensions use ;ext= format
  • URI-compliant

Example

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$number = $phoneUtil->parse('0117 496 0123', 'GB');

echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::RFC3966);
// Output: tel:+44-117-496-0123
$number = $phoneUtil->parse('+44 117 496 0123', null);
echo $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::RFC3966);
// Output: tel:+44-117-496-0123

When to Use RFC3966

Encode phone numbers in QR codes for easy scanning:
$telUri = $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::RFC3966);
// Generate QR code with: tel:+44-117-496-0123

Out-of-Country Formatting

Format numbers specifically for dialing from a different country using formatOutOfCountryCallingNumber():
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$ukNumber = $phoneUtil->parse('0117 496 0123', 'GB');

// Dialing from France (IDD prefix: 00)
echo $phoneUtil->formatOutOfCountryCallingNumber($ukNumber, 'FR');
// Output: 00 44 117 496 0123

// Dialing from US (IDD prefix: 011)
echo $phoneUtil->formatOutOfCountryCallingNumber($ukNumber, 'US');
// Output: 011 44 117 496 0123

// Dialing from within UK (uses national format)
echo $phoneUtil->formatOutOfCountryCallingNumber($ukNumber, 'GB');
// Output: 0117 496 0123

How It Works

The function automatically:
  1. Detects if the number is in the same country (uses NATIONAL format)
  2. Applies the correct IDD prefix for the calling country
  3. Formats according to local conventions
Different countries use different international dialing prefixes. The library handles this automatically.

Common IDD Prefixes

RegionIDD PrefixExample
Most of Europe0000 44 117 496 0123
United States011011 44 117 496 0123
Australia00110011 44 117 496 0123
Japan010010 44 117 496 0123
Brazil00 (with carrier)00XX 44 117 496 0123

Carrier Code Formatting

Some countries require carrier codes for certain calls:

Format with Specific Carrier

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$arNumber = $phoneUtil->parse('92234654321', 'AR');

// Format with carrier code "14"
echo $phoneUtil->formatNationalNumberWithCarrierCode($arNumber, '14');
// Output: 02234 14 65-4321

Format with Preferred Carrier

// Create number with preferred carrier
$arNumber = new \libphonenumber\PhoneNumber();
$arNumber->setCountryCode(54);
$arNumber->setNationalNumber('91234125678');
$arNumber->setPreferredDomesticCarrierCode('19');

// Use preferred carrier ("19"), or fallback to "15"
echo $phoneUtil->formatNationalNumberWithPreferredCarrierCode($arNumber, '15');
// Output: 01234 19 12-5678 (uses "19", not "15")

Mobile Dialing Format

Format numbers specifically for mobile device dialing:
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$auNumber = $phoneUtil->parse('1300123456', 'AU');

// Format for dialing from within Australia
echo $phoneUtil->formatNumberForMobileDialing($auNumber, 'AU', true);
// Output: 1300 123 456

// Unformatted version
echo $phoneUtil->formatNumberForMobileDialing($auNumber, 'AU', false);
// Output: 1300123456

// Cannot be dialed from US (returns empty string)
echo $phoneUtil->formatNumberForMobileDialing($auNumber, 'US', true);
// Output: ""
If formatNumberForMobileDialing() returns an empty string, the number cannot be dialed from that region (e.g., domestic-only numbers).

Choosing the Right Format

Use E164
// ✅ Best for databases
$e164 = $phoneUtil->format(
    $number, 
    \libphonenumber\PhoneNumberFormat::E164
);
Benefits:
  • No ambiguity
  • Easy to index
  • Consistent across all numbers

Best Practices

Always store phone numbers in E.164 format in your database, then format them for display based on context.
// ✅ Good: Store E164, display formatted
$e164 = $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::E164);
$db->save($e164);

// Later, for display:
$number = $phoneUtil->parse($e164, null);
$display = $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);

// ❌ Bad: Store formatted display version
$national = $phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::NATIONAL);
$db->save($national); // Loses country information!

Build docs developers (and LLMs) love