PHPackages                             dunrocom/libphonenumber-for-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. dunrocom/libphonenumber-for-php

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

dunrocom/libphonenumber-for-php
===============================

PHP Port of Google's libphonenumber

8.9.5(7y ago)02772Apache-2.0PHPPHP &gt;=5.3.2

Since Jul 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dunro/libphonenumber-for-php)[ Packagist](https://packagist.org/packages/dunrocom/libphonenumber-for-php)[ Docs](https://github.com/dunro/libphonenumber-for-php)[ RSS](/packages/dunrocom-libphonenumber-for-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (8)Versions (97)Used By (0)

libphonenumber for PHP [![Build Status](https://camo.githubusercontent.com/a12f54cd5a8b6f0ba8c8a868de765bd3931315264f2c850d951afb3b22a442ed/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f676967677365792f6c696270686f6e656e756d6265722d666f722d7068702e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/giggsey/libphonenumber-for-php) [![Coverage Status](https://camo.githubusercontent.com/9eaabd66678ed18050c9ba405ad36265a476c76e4efd8c8bd9293134959359dd/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f676967677365792f6c696270686f6e656e756d6265722d666f722d7068702e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/giggsey/libphonenumber-for-php?branch=master)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#libphonenumber-for-php--)

[![Total Downloads](https://camo.githubusercontent.com/d176dbde7ad18ea4c125c4a4a4aaf0c6e1e2797e3bbf7af4032512ff9cccab1b/68747470733a2f2f706f7365722e707567782e6f72672f676967677365792f6c696270686f6e656e756d6265722d666f722d7068702f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/giggsey/libphonenumber-for-php)[![Downloads per month](https://camo.githubusercontent.com/adefa8e127f58bec3077e2a4bb8f0f4c6633eaa373d5bd4329bf501eda4c7e47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f676967677365792f6c696270686f6e656e756d6265722d666f722d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/giggsey/libphonenumber-for-php)[![Latest Stable Version](https://camo.githubusercontent.com/497b27a1b12c1dbdbce95e08e4586c524455c6613f44795d4c571ebc38aa20f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676967677365792f6c696270686f6e656e756d6265722d666f722d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/giggsey/libphonenumber-for-php)[![License](https://camo.githubusercontent.com/fc5c1ae0368635c992dc3ed8a0c39d057d41933439935c859495c777e051e405/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d7265642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/giggsey/libphonenumber-for-php)

What is it?
-----------

[](#what-is-it)

A PHP library for parsing, formatting, storing and validating international phone numbers. This library is based on Google's [libphonenumber](https://github.com/googlei18n/libphonenumber).

- [Installation](#installation)
- [Documentation](#documentation)
- [Online Demo](#online-demo)
- [Highlights of functionality](#highlights-of-functionality)
    - [Versioning](#versioning)
    - [Quick Examples](#quick-examples)
        - [Geocoder](#geocoder)
        - [ShortNumberInfo](#shortnumberinfo)
        - [Mapping Phone Numbers to carrier](#mapping-phone-numbers-to-carrier)
        - [Mapping Phone Numbers to TimeZones](#mapping-phone-numbers-to-timezones)
- [FAQ](#faq)
    - [Problems with Invalid Numbers?](#problems-with-invalid-numbers)
- [Generating data](#generating-data)
- [Integration with frameworks](#integration-with-frameworks)

Installation
------------

[](#installation)

PHP versions 5.3 up to PHP 7.2 are currently supported. HHVM is also supported.

The PECL [mbstring](http://php.net/mbstring) extension is required.

It is recommended to use [composer](https://getcomposer.org) to install the library.

```
$ composer require giggsey/libphonenumber-for-php
```

You can also use any other [PSR-4](http://www.php-fig.org/psr/psr-4/) compliant autoloader.

If you do not use composer, ensure that you also load any dependencies that this project has, such as [giggsey/locale](https://github.com/giggsey/Locale).

Documentation
-------------

[](#documentation)

- [PhoneNumber Util](docs/PhoneNumberUtil.md)
- [ShortNumber Info](docs/ShortNumberInfo.md)
- [Phone Number Geolocation](docs/PhoneNumberOfflineGeocoder.md)
- [Phone Number to Carrier Mapping](docs/PhoneNumberToCarrierMapper.md)
- [Phone Number to Timezone Mapping](docs/PhoneNumberToTimeZonesMapper.md)
- [Phone Number Matcher](docs/PhoneNumberMatcher.md)
- [As You Type Formatter](docs/AsYouTypeFormatter.md)

Online Demo
-----------

[](#online-demo)

An [online demo](http://giggsey.com/libphonenumber/) is available, and the source can be found at [giggsey/libphonenumber-example](https://github.com/giggsey/libphonenumber-example).

Highlights of functionality
===========================

[](#highlights-of-functionality)

- Parsing/formatting/validating phone numbers for all countries/regions of the world.
- `getNumberType` - gets the type of the number based on the number itself; able to distinguish Fixed-line, Mobile, Toll-free, Premium Rate, Shared Cost, VoIP and Personal Numbers (whenever feasible).
- `isNumberMatch` - gets a confidence level on whether two numbers could be the same.
- `getExampleNumber`/`getExampleNumberByType` - provides valid example numbers for all countries/regions, with the option of specifying which type of example phone number is needed.
- `isValidNumber` - full validation of a phone number for a region using length and prefix information.
- `PhoneNumberOfflineGeocoder` - provides geographical information related to a phone number.
- `PhoneNumberToTimeZonesMapper` - provides timezone information related to a phone number.
- `PhoneNumberToCarrierMapper` - provides carrier information related to a phone number.

Versioning
----------

[](#versioning)

This library will try to follow the same version numbers as Google. There could be additional releases where needed to fix critical issues that can not wait until the next release from Google.

This does mean that this project may not follow [Semantic Versioning](http://semver.org/), but instead Google's version policy. As a result, jumps in major versions may not actually contain any backwards incompatible changes. Please read the release notes for such releases.

Google try to release their versions according to Semantic Versioning, as laid out of in their [Versioning Guide](https://github.com/googlei18n/libphonenumber#versioning-and-announcements).

Quick Examples
--------------

[](#quick-examples)

Let's say you have a string representing a phone number from Switzerland. This is how you parse/normalize it into a PhoneNumber object:

```
$swissNumberStr = "044 668 18 00";
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
try {
    $swissNumberProto = $phoneUtil->parse($swissNumberStr, "CH");
    var_dump($swissNumberProto);
} catch (\libphonenumber\NumberParseException $e) {
    var_dump($e);
}
```

At this point, swissNumberProto contains:

```
class libphonenumber\PhoneNumber#9 (7) {
 private $countryCode =>
  int(41)
 private $nationalNumber =>
  double(446681800)
 private $extension =>
  NULL
 private $italianLeadingZero =>
  NULL
 private $rawInput =>
  NULL
 private $countryCodeSource =>
  NULL
 private $preferredDomesticCarrierCode =>
  NULL
}

```

Now let us validate whether the number is valid:

```
$isValid = $phoneUtil->isValidNumber($swissNumberProto);
var_dump($isValid); // true
```

There are a few formats supported by the formatting method, as illustrated below:

```
// Produces "+41446681800"
echo $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::E164);

// Produces "044 668 18 00"
echo $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::NATIONAL);

// Produces "+41 44 668 18 00"
echo $phoneUtil->format($swissNumberProto, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);
```

You could also choose to format the number in the way it is dialled from another country:

```
// Produces "011 41 44 668 1800", the number when it is dialled in the United States.
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "US");

// Produces "00 41 44 668 18 00", the number when it is dialled in Great Britain.
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "GB");
```

### Geocoder

[](#geocoder)

```
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();

$swissNumberProto = $phoneUtil->parse("044 668 18 00", "CH");
$usNumberProto = $phoneUtil->parse("+1 650 253 0000", "US");
$gbNumberProto = $phoneUtil->parse("0161 496 0000", "GB");

$geocoder = \libphonenumber\geocoding\PhoneNumberOfflineGeocoder::getInstance();

// Outputs "Zurich"
echo $geocoder->getDescriptionForNumber($swissNumberProto, "en_US");

// Outputs "Zürich"
echo $geocoder->getDescriptionForNumber($swissNumberProto, "de_DE");

// Outputs "Zurigo"
echo $geocoder->getDescriptionForNumber($swissNumberProto, "it_IT");

// Outputs "Mountain View, CA"
echo $geocoder->getDescriptionForNumber($usNumberProto, "en_US");

// Outputs "Mountain View, CA"
echo $geocoder->getDescriptionForNumber($usNumberProto, "de_DE");

// Outputs "미국" (Korean for United States)
echo $geocoder->getDescriptionForNumber($usNumberProto, "ko-KR");

// Outputs "Manchester"
echo $geocoder->getDescriptionForNumber($gbNumberProto, "en_GB");

// Outputs "영국" (Korean for United Kingdom)
echo $geocoder->getDescriptionForNumber($gbNumberProto, "ko-KR");
```

### ShortNumberInfo

[](#shortnumberinfo)

```
$shortNumberInfo = \libphonenumber\ShortNumberInfo::getInstance();

// true
var_dump($shortNumberInfo->isEmergencyNumber("999", "GB"));

// true
var_dump($shortNumberInfo->connectsToEmergencyNumber("999", "GB"));

// false
var_dump($shortNumberInfo->connectsToEmergencyNumber("911", "GB"));

// true
var_dump($shortNumberInfo->isEmergencyNumber("911", "US"));

// true
var_dump($shortNumberInfo->connectsToEmergencyNumber("911", "US"));

// false
var_dump($shortNumberInfo->isEmergencyNumber("911123", "US"));

// true
var_dump($shortNumberInfo->connectsToEmergencyNumber("911123", "US"));
```

### Mapping Phone Numbers to carrier

[](#mapping-phone-numbers-to-carrier)

```
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$swissNumberProto = $phoneUtil->parse("798765432", "CH");

$carrierMapper = \libphonenumber\PhoneNumberToCarrierMapper::getInstance();
// Outputs "Swisscom"
echo $carrierMapper->getNameForNumber($swissNumberProto, "en");
```

### Mapping Phone Numbers to TimeZones

[](#mapping-phone-numbers-to-timezones)

```
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$swissNumberProto = $phoneUtil->parse("798765432", "CH");

$timeZoneMapper = \libphonenumber\PhoneNumberToTimeZonesMapper::getInstance();
// returns array("Europe/Zurich")
$timeZones = $timeZoneMapper->getTimeZonesForNumber($swissNumberProto);
```

FAQ
---

[](#faq)

#### Problems with Invalid Numbers?

[](#problems-with-invalid-numbers)

This library uses phone number metadata from Google's [libphonenumber](https://github.com/googlei18n/libphonenumber). If this library is working as intended, it should provide the same result as the Java version of Google's project.

If you believe that a phone number is returning an incorrect result, first test it with [libphonenumber](https://github.com/googlei18n/libphonenumber) via their [Online Demo](https://libphonenumber.appspot.com/). If that returns the same result as this project, and you feel it is in error, raise it as an Issue with the libphonenumber project.

If Google's [Online Demo](https://libphonenumber.appspot.com/) gives a different result to the [libphonenumber-for-php demo](http://giggsey.com/libphonenumber/), then please raise an Issue here.

Generating data
---------------

[](#generating-data)

Generating the data is not normally needed, as this repository will generally always have the up to data metadata.

If you do need to generate the data, the commands are provided by [Phing](https://www.phing.info). Ensure you have all the dev composer dependencies installed, then run

```
$ vendor/bin/phing compile
```

This compile process clones the [libphonenumber](https://github.com/googlei18n/libphonenumber) project at the version specified in [METADATA-VERSION.txt](METADATA-VERSION.txt).

Integration with frameworks
---------------------------

[](#integration-with-frameworks)

Other packages exist that integrate libphonenumber-for-php into frameworks.

FrameworkPackagesSymfony[PhoneNumberBundle](https://github.com/misd-service-development/phone-number-bundle)Laravel[Laravel Phone](https://github.com/Propaganistas/Laravel-Phone)Yii2[PhoneInput](https://github.com/Borales/yii2-phone-input)Kohana[PhoneNumber](https://github.com/softmediadev/kohana-phonenumber)These packages are supplied by third parties, and their quality can not be guaranteed.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 71.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~21 days

Recently: every ~82 days

Total

96

Last Release

2657d ago

Major Versions

5.9.4 → 6.02014-02-26

6.3.1 → 7.02014-11-03

7.7.5 → 8.02016-12-12

PHP version history (2 changes)7.4.3PHP &gt;=5.3

7.5.0PHP &gt;=5.3.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f405b8b82266cafaac05e56ccbbc3d263b2b4a2adf703f2e0dba42a38744d0f1?d=identicon)[marzieh\_tajik](/maintainers/marzieh_tajik)

---

Top Contributors

[![giggsey](https://avatars.githubusercontent.com/u/305730?v=4)](https://github.com/giggsey "giggsey (447 commits)")[![davideme](https://avatars.githubusercontent.com/u/858090?v=4)](https://github.com/davideme "davideme (71 commits)")[![justjkk](https://avatars.githubusercontent.com/u/192893?v=4)](https://github.com/justjkk "justjkk (22 commits)")[![ajayrungta](https://avatars.githubusercontent.com/u/394210?v=4)](https://github.com/ajayrungta "ajayrungta (22 commits)")[![Nephele](https://avatars.githubusercontent.com/u/3705856?v=4)](https://github.com/Nephele "Nephele (12 commits)")[![joshuagiggxon](https://avatars.githubusercontent.com/u/35339413?v=4)](https://github.com/joshuagiggxon "joshuagiggxon (5 commits)")[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (4 commits)")[![BenjaminHoegh](https://avatars.githubusercontent.com/u/22152591?v=4)](https://github.com/BenjaminHoegh "BenjaminHoegh (4 commits)")[![zoloft](https://avatars.githubusercontent.com/u/2939780?v=4)](https://github.com/zoloft "zoloft (3 commits)")[![cafferata](https://avatars.githubusercontent.com/u/1150425?v=4)](https://github.com/cafferata "cafferata (3 commits)")[![farzan](https://avatars.githubusercontent.com/u/196105?v=4)](https://github.com/farzan "farzan (3 commits)")[![tom-1bg](https://avatars.githubusercontent.com/u/11245840?v=4)](https://github.com/tom-1bg "tom-1bg (3 commits)")[![regius-cirruspath](https://avatars.githubusercontent.com/u/19675221?v=4)](https://github.com/regius-cirruspath "regius-cirruspath (2 commits)")[![captn3m0](https://avatars.githubusercontent.com/u/584253?v=4)](https://github.com/captn3m0 "captn3m0 (2 commits)")[![thewilkybarkid](https://avatars.githubusercontent.com/u/1784740?v=4)](https://github.com/thewilkybarkid "thewilkybarkid (2 commits)")[![boekkooi](https://avatars.githubusercontent.com/u/399895?v=4)](https://github.com/boekkooi "boekkooi (2 commits)")[![abhinavlal](https://avatars.githubusercontent.com/u/445119?v=4)](https://github.com/abhinavlal "abhinavlal (2 commits)")[![iGusev](https://avatars.githubusercontent.com/u/1555767?v=4)](https://github.com/iGusev "iGusev (2 commits)")[![antonkomarev](https://avatars.githubusercontent.com/u/1849174?v=4)](https://github.com/antonkomarev "antonkomarev (2 commits)")[![steffkes](https://avatars.githubusercontent.com/u/325361?v=4)](https://github.com/steffkes "steffkes (1 commits)")

---

Tags

validationgeocodinggeolocationlibphonenumbermobilephonenumber

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dunrocom-libphonenumber-for-php/health.svg)

```
[![Health](https://phpackages.com/badges/dunrocom-libphonenumber-for-php/health.svg)](https://phpackages.com/packages/dunrocom-libphonenumber-for-php)
```

###  Alternatives

[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M415](/packages/giggsey-libphonenumber-for-php)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8412.9M47](/packages/giggsey-libphonenumber-for-php-lite)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M106](/packages/propaganistas-laravel-phone)[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k489.6M671](/packages/composer-semver)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M381](/packages/respect-validation)[opis/json-schema

Json Schema Validator for PHP

64236.9M185](/packages/opis-json-schema)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
