Skip to main content

Welcome to libphonenumber for PHP

libphonenumber for PHP is a comprehensive library for parsing, formatting, storing and validating international phone numbers. This is a PHP port of Google’s libphonenumber library, providing the same powerful phone number handling capabilities to the PHP ecosystem.

Quick Start

Get up and running in minutes with our quick start guide

API Reference

Explore the complete API documentation

Guides

Learn best practices and common patterns

Framework Integration

Integrate with Symfony, Laravel, and more

Key Features

Parse & Validate

Parse phone numbers from any format and validate them against international standards

Format Numbers

Format numbers for E.164, international, national, and RFC3966 formats

Geocoding

Get geographic location information for phone numbers

Carrier Mapping

Identify the carrier for mobile phone numbers

Timezone Mapping

Determine timezone information from phone numbers

Emergency Numbers

Handle short codes and emergency numbers correctly

As-You-Type

Format phone numbers in real-time as users type

Find Numbers

Extract phone numbers from text content

Why Use This Library?

This library is a direct port of Google’s authoritative libphonenumber library, ensuring accurate and up-to-date phone number handling for 250+ countries and territories worldwide.
With over 5,000 stars on GitHub and millions of downloads via Composer, this library is battle-tested and trusted by developers worldwide.
Regular updates keep the library in sync with Google’s libphonenumber releases, ensuring you always have the latest phone number metadata and validation rules.
Comprehensive documentation, code examples, and community support make it easy to integrate phone number validation into your application.

Requirements

  • PHP: 8.1 to 8.5
  • Extensions: mbstring (PECL extension)
  • Dependencies: Automatically managed by Composer
This library follows Google’s versioning and may not strictly adhere to Semantic Versioning. Major version jumps may not contain backwards-incompatible changes. Always review release notes.

Quick Example

Here’s a simple example of parsing and validating a phone number:
use libphonenumber\PhoneNumberUtil;

$phoneUtil = PhoneNumberUtil::getInstance();

try {
    // Parse a Swiss phone number
    $numberProto = $phoneUtil->parse("044 668 18 00", "CH");
    
    // Validate the number
    $isValid = $phoneUtil->isValidNumber($numberProto);
    var_dump($isValid); // bool(true)
    
    // Format in different styles
    echo $phoneUtil->format($numberProto, \libphonenumber\PhoneNumberFormat::E164);
    // Output: +41446681800
    
    echo $phoneUtil->format($numberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
    // Output: +41 44 668 18 00
    
} catch (\libphonenumber\NumberParseException $e) {
    echo "Error parsing number: " . $e->getMessage();
}

Next Steps

1

Install the library

Follow the installation guide to add libphonenumber to your project
2

Learn the basics

Work through the quickstart guide to understand core concepts
3

Explore features

Check out our guides for common use cases and patterns
4

Deep dive into the API

Browse the API reference for detailed documentation

Community and Support

If you only need core phone number utilities without geocoding or carrier mapping, consider using giggsey/libphonenumber-for-php-lite for a smaller package size.

Build docs developers (and LLMs) love