Skip to main content

Overview

The PhoneNumberFormat enum defines the different formats in which phone numbers can be displayed. These constants are used with the PhoneNumberUtil::format() method to control the output format.
enum PhoneNumberFormat: int
{
    case E164 = 0;
    case INTERNATIONAL = 1;
    case NATIONAL = 2;
    case RFC3966 = 3;
}

Format Types

E164

The E.164 format is the international standard for telephone number formatting. It produces a compact, machine-readable format with no spaces or formatting characters. Format: +[country code][national number]
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

$phoneNumberUtil = PhoneNumberUtil::getInstance();
$numberProto = $phoneNumberUtil->parse('+41 44 668 1800', 'CH');

echo $phoneNumberUtil->format($numberProto, PhoneNumberFormat::E164);
// Output: +41446681800
When to use:
  • Storing phone numbers in databases
  • API communication and data exchange
  • SMS/telephony systems that require standardized format
  • Any scenario requiring a canonical, unambiguous representation
E164 format is highly recommended for storage as it’s neutral, compact, and internationally recognized.

INTERNATIONAL

The INTERNATIONAL format is consistent with ITU-T Recommendation E.123 and provides a human-readable format with proper spacing for international use. Format: +[country code] [formatted national number]
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

$phoneNumberUtil = PhoneNumberUtil::getInstance();
$numberProto = $phoneNumberUtil->parse('044 668 1800', 'CH');

echo $phoneNumberUtil->format($numberProto, PhoneNumberFormat::INTERNATIONAL);
// Output: +41 44 668 1800
When to use:
  • Displaying phone numbers to users in an international context
  • Contact information on websites with global audiences
  • Business cards and marketing materials for international use
  • Email signatures for international companies

NATIONAL

The NATIONAL format displays the phone number as it would be dialed within its home country, including any necessary national prefix but without the country code. Format: [national prefix][formatted national number]
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

$phoneNumberUtil = PhoneNumberUtil::getInstance();
$numberProto = $phoneNumberUtil->parse('+41 44 668 1800', 'CH');

echo $phoneNumberUtil->format($numberProto, PhoneNumberFormat::NATIONAL);
// Output: 044 668 1800
When to use:
  • Displaying phone numbers to users within the same country
  • Local business listings and directories
  • Forms and applications where the country context is known
  • Print materials for domestic audiences
NATIONAL format should only be used when you’re certain the number will be dialed from within the same country. For international contexts, always use INTERNATIONAL or E164 format.

RFC3966

The RFC3966 format follows the RFC 3966 standard for representing telephone numbers as URIs. This format is designed for use in hyperlinks and web-based telephony applications. Format: tel:+[country code]-[formatted national number][;ext=[extension]]
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

$phoneNumberUtil = PhoneNumberUtil::getInstance();
$numberProto = $phoneNumberUtil->parse('+41 44 668 1800', 'CH');

echo $phoneNumberUtil->format($numberProto, PhoneNumberFormat::RFC3966);
// Output: tel:+41-44-668-1800
When to use:
  • Creating clickable phone links in HTML (<a href="tel:..."> tags)
  • Mobile-friendly web applications
  • QR codes containing phone numbers
  • Any URI-based telephony application
<?php
$formatted = $phoneNumberUtil->format($numberProto, PhoneNumberFormat::RFC3966);
?>
<a href="<?= $formatted ?>"><?= $phoneNumberUtil->format($numberProto, PhoneNumberFormat::INTERNATIONAL) ?></a>

Format Comparison

Here’s a side-by-side comparison of all formats for the same phone number:
use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

$phoneNumberUtil = PhoneNumberUtil::getInstance();
$number = $phoneNumberUtil->parse('+41 44 668 1800', 'CH');

echo "E164: " . $phoneNumberUtil->format($number, PhoneNumberFormat::E164) . "\n";
// +41446681800

echo "INTERNATIONAL: " . $phoneNumberUtil->format($number, PhoneNumberFormat::INTERNATIONAL) . "\n";
// +41 44 668 1800

echo "NATIONAL: " . $phoneNumberUtil->format($number, PhoneNumberFormat::NATIONAL) . "\n";
// 044 668 1800

echo "RFC3966: " . $phoneNumberUtil->format($number, PhoneNumberFormat::RFC3966) . "\n";
// tel:+41-44-668-1800

Quick Reference Table

FormatUse CaseExample (Swiss)ClickableStorage
E164Storage, APIs+41446681800No✅ Recommended
INTERNATIONALDisplay (global)+41 44 668 1800NoNot recommended
NATIONALDisplay (local)044 668 1800No❌ Not recommended
RFC3966Web links, URIstel:+41-44-668-1800✅ YesNot recommended

Best Practices

For Storage: Always store phone numbers in E164 format in your database. This ensures consistency, simplifies searching, and makes international handling straightforward.
For Display: Choose the format based on your audience:
  • INTERNATIONAL for multi-country applications
  • NATIONAL when the user’s country matches the number’s country
  • RFC3966 for clickable phone links

Example: Smart Formatting Based on Context

use libphonenumber\PhoneNumberUtil;
use libphonenumber\PhoneNumberFormat;

function formatPhoneForUser($phoneNumber, $userCountry) {
    $phoneNumberUtil = PhoneNumberUtil::getInstance();
    $numberProto = $phoneNumberUtil->parse($phoneNumber, null);
    
    // Get the number's region
    $numberRegion = $phoneNumberUtil->getRegionCodeForNumber($numberProto);
    
    // Use NATIONAL format if user is in the same country, otherwise INTERNATIONAL
    if ($numberRegion === $userCountry) {
        return $phoneNumberUtil->format($numberProto, PhoneNumberFormat::NATIONAL);
    } else {
        return $phoneNumberUtil->format($numberProto, PhoneNumberFormat::INTERNATIONAL);
    }
}

// Examples
echo formatPhoneForUser('+41446681800', 'CH'); // "044 668 1800" (national)
echo formatPhoneForUser('+41446681800', 'US'); // "+41 44 668 1800" (international)

Build docs developers (and LLMs) love