PHPackages                             lucas-simas/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. lucas-simas/libphonenumber-for-php

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

lucas-simas/libphonenumber-for-php
==================================

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

9.0.26(1mo ago)02↓100%Apache-2.0PHPPHP ^8.1

Since Jul 24Pushed 1mo agoCompare

[ Source](https://github.com/lucas-simas/libphonenumber-for-php)[ Packagist](https://packagist.org/packages/lucas-simas/libphonenumber-for-php)[ Docs](https://github.com/giggsey/libphonenumber-for-php)[ RSS](/packages/lucas-simas-libphonenumber-for-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (15)Versions (284)Used By (0)

libphonenumber for PHP [![Build Status](https://github.com/giggsey/libphonenumber-for-php/workflows/Continuous%20Integration/badge.svg)](https://github.com/giggsey/libphonenumber-for-php/actions?query=workflow%3A%22Continuous+Integration%22) [![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/25524f6af11190841a6f92c8df1c414285cbf089df2feadb14230c96d872d4f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d7265642e7376673f7374796c653d666c61742d737175617265)](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/google/libphonenumber).

- [Installation](#installation)
- [Documentation](#documentation)
- [Online Demo](#online-demo)
- [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 8.1 to 8.5 are currently 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).

giggsey/libphonenumber-for-php-lite
-----------------------------------

[](#giggseylibphonenumber-for-php-lite)

If you only want to make use of the core PhoneNumber Util functionality, you can use [giggsey/libphonenumber-for-php-lite](https://github.com/giggsey/libphonenumber-for-php-lite), which offers a much smaller package size.

### PHP Version Policy

[](#php-version-policy)

This library will be updated to use [supported versions of PHP](https://www.php.net/supported-versions.php) without major version bumps.

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).

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/google/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/google/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/google/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 date metadata.

To compile the data, run the composer script 'build'

```
composer run build
```

This build process clones the [libphonenumber](https://github.com/google/libphonenumber) project at the version specified in [METADATA-VERSION.php](METADATA-VERSION.php).

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

[](#integration-with-frameworks)

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

FrameworkPackagesSymfony[PhoneNumberBundle](https://github.com/odolbeau/phone-number-bundle)Laravel[Laravel Phone](https://github.com/Propaganistas/Laravel-Phone)TYPO3[TYPO3 Phone Extension](https://github.com/simonschaufi/typo3-phone)These packages are supplied by third parties, and their quality can not be guaranteed.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance96

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 84.3% 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 ~16 days

Recently: every ~6 days

Total

283

Last Release

50d ago

Major Versions

5.9.4 → 6.02014-02-26

6.3.1 → 7.02014-11-03

7.7.5 → 8.02016-12-12

8.13.55 → 9.0.02025-03-19

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

7.5.0PHP &gt;=5.3.2

8.13.47PHP ^7.4|^8.0

9.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e681b863507c16dbe0167a0bdd704f95b9c1b10a235459a4d95e2e63bf8ab959?d=identicon)[lucas-simas](/maintainers/lucas-simas)

---

Top Contributors

[![giggsey](https://avatars.githubusercontent.com/u/305730?v=4)](https://github.com/giggsey "giggsey (1024 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)")[![BenMorel](https://avatars.githubusercontent.com/u/1952838?v=4)](https://github.com/BenMorel "BenMorel (12 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)")[![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)")[![garak](https://avatars.githubusercontent.com/u/179866?v=4)](https://github.com/garak "garak (3 commits)")[![stollr](https://avatars.githubusercontent.com/u/1118790?v=4)](https://github.com/stollr "stollr (3 commits)")[![tom-1bg](https://avatars.githubusercontent.com/u/11245840?v=4)](https://github.com/tom-1bg "tom-1bg (3 commits)")[![omahm](https://avatars.githubusercontent.com/u/1013025?v=4)](https://github.com/omahm "omahm (2 commits)")[![regius-cirruspath](https://avatars.githubusercontent.com/u/19675221?v=4)](https://github.com/regius-cirruspath "regius-cirruspath (2 commits)")[![abhinavlal](https://avatars.githubusercontent.com/u/445119?v=4)](https://github.com/abhinavlal "abhinavlal (2 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (2 commits)")[![thewilkybarkid](https://avatars.githubusercontent.com/u/1784740?v=4)](https://github.com/thewilkybarkid "thewilkybarkid (2 commits)")[![gsteel](https://avatars.githubusercontent.com/u/2803720?v=4)](https://github.com/gsteel "gsteel (2 commits)")[![iGusev](https://avatars.githubusercontent.com/u/1555767?v=4)](https://github.com/iGusev "iGusev (2 commits)")

---

Tags

validationgeocodinggeolocationlibphonenumbermobilephonenumber

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/lucas-simas-libphonenumber-for-php/health.svg)](https://phpackages.com/packages/lucas-simas-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.7M414](/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)[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M379](/packages/respect-validation)[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)[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)
