{"id":21744007,"url":"https://github.com/telefonica/libphonenumber-php","last_synced_at":"2026-05-14T23:40:05.001Z","repository":{"id":66221925,"uuid":"125395301","full_name":"Telefonica/libphonenumber-php","owner":"Telefonica","description":null,"archived":false,"fork":false,"pushed_at":"2018-03-16T11:25:41.000Z","size":12167,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":61,"default_branch":"master","last_synced_at":"2025-01-25T22:21:40.616Z","etag":null,"topics":["cdco"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Telefonica.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-15T16:24:17.000Z","updated_at":"2021-09-27T08:20:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"5e76f20c-ae72-4f7d-aec4-c34457bb4fb2","html_url":"https://github.com/Telefonica/libphonenumber-php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Flibphonenumber-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Flibphonenumber-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Flibphonenumber-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Telefonica%2Flibphonenumber-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Telefonica","download_url":"https://codeload.github.com/Telefonica/libphonenumber-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244722653,"owners_count":20499151,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cdco"],"created_at":"2024-11-26T07:09:43.536Z","updated_at":"2026-05-14T23:39:59.979Z","avatar_url":"https://github.com/Telefonica.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libphonenumber for PHP [![Build Status](https://img.shields.io/travis/giggsey/libphonenumber-for-php.svg?style=flat-square)](https://travis-ci.org/giggsey/libphonenumber-for-php) [![Coverage Status](https://img.shields.io/coveralls/giggsey/libphonenumber-for-php.svg?style=flat-square)](https://coveralls.io/r/giggsey/libphonenumber-for-php?branch=master)\n\n[![Total Downloads](https://poser.pugx.org/giggsey/libphonenumber-for-php/downloads?format=flat-square)](https://packagist.org/packages/giggsey/libphonenumber-for-php)\n[![Downloads per month](https://img.shields.io/packagist/dm/giggsey/libphonenumber-for-php.svg?style=flat-square)](https://packagist.org/packages/giggsey/libphonenumber-for-php)\n[![Latest Stable Version](https://img.shields.io/packagist/v/giggsey/libphonenumber-for-php.svg?style=flat-square)](https://packagist.org/packages/giggsey/libphonenumber-for-php)\n[![License](http://img.shields.io/badge/license-Apache%202.0-red.svg?style=flat-square)](https://packagist.org/packages/giggsey/libphonenumber-for-php)\n\n## What is it?\nA PHP library for parsing, formatting, storing and validating international phone numbers. This library is based on Google's [libphonenumber](https://github.com/googlei18n/libphonenumber).\n\n\n\n - [Installation](#installation)\n - [Documentation](#documentation)\n - [Online Demo](#online-demo)\n - [Highlights of functionality](#highlights-of-functionality)\n   - [Versioning](#versioning)\n   - [Quick Examples](#quick-examples)\n     - [Geocoder](#geocoder)\n     - [ShortNumberInfo](#shortnumberinfo)\n     - [Mapping Phone Numbers to carrier](#mapping-phone-numbers-to-carrier)\n     - [Mapping Phone Numbers to TimeZones](#mapping-phone-numbers-to-timezones)\n - [FAQ](#faq)\n   - [Problems with Invalid Numbers?](#problems-with-invalid-numbers)\n - [Generating data](#generating-data)\n - [Integration with frameworks](#integration-with-frameworks)\n\n\n## Installation\n\nPHP versions 5.3 up to PHP 7.2 are currently supported. HHVM is also supported.\n\nThe PECL [mbstring](http://php.net/mbstring) extension is required.\n\nIt is recommended to use [composer](https://getcomposer.org) to install the library.\n\n```bash\n$ composer require giggsey/libphonenumber-for-php\n```\n\nYou can also use any other [PSR-4](http://www.php-fig.org/psr/psr-4/) compliant autoloader.\n\nIf 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).\n\n## Documentation\n\n - [PhoneNumber Util](docs/PhoneNumberUtil.md)\n - [ShortNumber Info](docs/ShortNumberInfo.md)\n - [Phone Number Geolocation](docs/PhoneNumberOfflineGeocoder.md)\n - [Phone Number to Carrier Mapping](docs/PhoneNumberToCarrierMapper.md)\n - [Phone Number to Timezone Mapping](docs/PhoneNumberToTimeZonesMapper.md)\n - [Phone Number Matcher](docs/PhoneNumberMatcher.md)\n - [As You Type Formatter](docs/AsYouTypeFormatter.md)\n\n## Online Demo\nAn [online demo](http://giggsey.com/libphonenumber/) is available, and the source can be found at [giggsey/libphonenumber-example](https://github.com/giggsey/libphonenumber-example).\n\n# Highlights of functionality\n* Parsing/formatting/validating phone numbers for all countries/regions of the world.\n* `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).\n* `isNumberMatch` - gets a confidence level on whether two numbers could be the same.\n* `getExampleNumber`/`getExampleNumberByType` - provides valid example numbers for all countries/regions, with the option of specifying which type of example phone number is needed.\n* `isValidNumber` - full validation of a phone number for a region using length and prefix information.\n* `PhoneNumberOfflineGeocoder` - provides geographical information related to a phone number.\n* `PhoneNumberToTimeZonesMapper` - provides timezone information related to a phone number.\n* `PhoneNumberToCarrierMapper` - provides carrier information related to a phone number.\n\n## Versioning\n\nThis 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.\n\nThis 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\nincompatible changes. Please read the release notes for such releases.\n\nGoogle 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).\n\n## Quick Examples\nLet's say you have a string representing a phone number from Switzerland. This is how you parse/normalize it into a PhoneNumber object:\n\n```php\n$swissNumberStr = \"044 668 18 00\";\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\ntry {\n    $swissNumberProto = $phoneUtil-\u003eparse($swissNumberStr, \"CH\");\n    var_dump($swissNumberProto);\n} catch (\\libphonenumber\\NumberParseException $e) {\n    var_dump($e);\n}\n```\n\nAt this point, swissNumberProto contains:\n\n    class libphonenumber\\PhoneNumber#9 (7) {\n     private $countryCode =\u003e\n      int(41)\n     private $nationalNumber =\u003e\n      double(446681800)\n     private $extension =\u003e\n      NULL\n     private $italianLeadingZero =\u003e\n      NULL\n     private $rawInput =\u003e\n      NULL\n     private $countryCodeSource =\u003e\n      NULL\n     private $preferredDomesticCarrierCode =\u003e\n      NULL\n    }\n\nNow let us validate whether the number is valid:\n\n```php\n$isValid = $phoneUtil-\u003eisValidNumber($swissNumberProto);\nvar_dump($isValid); // true\n```\n\nThere are a few formats supported by the formatting method, as illustrated below:\n\n```php\n// Produces \"+41446681800\"\necho $phoneUtil-\u003eformat($swissNumberProto, \\libphonenumber\\PhoneNumberFormat::E164);\n\n// Produces \"044 668 18 00\"\necho $phoneUtil-\u003eformat($swissNumberProto, \\libphonenumber\\PhoneNumberFormat::NATIONAL);\n\n// Produces \"+41 44 668 18 00\"\necho $phoneUtil-\u003eformat($swissNumberProto, \\libphonenumber\\PhoneNumberFormat::INTERNATIONAL);\n```\n\nYou could also choose to format the number in the way it is dialled from another country:\n\n```php\n// Produces \"011 41 44 668 1800\", the number when it is dialled in the United States.\necho $phoneUtil-\u003eformatOutOfCountryCallingNumber($swissNumberProto, \"US\");\n\n// Produces \"00 41 44 668 18 00\", the number when it is dialled in Great Britain.\necho $phoneUtil-\u003eformatOutOfCountryCallingNumber($swissNumberProto, \"GB\");\n```\n\n### Geocoder\n\n```php\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\n\n$swissNumberProto = $phoneUtil-\u003eparse(\"044 668 18 00\", \"CH\");\n$usNumberProto = $phoneUtil-\u003eparse(\"+1 650 253 0000\", \"US\");\n$gbNumberProto = $phoneUtil-\u003eparse(\"0161 496 0000\", \"GB\");\n\n$geocoder = \\libphonenumber\\geocoding\\PhoneNumberOfflineGeocoder::getInstance();\n\n// Outputs \"Zurich\"\necho $geocoder-\u003egetDescriptionForNumber($swissNumberProto, \"en_US\");\n\n// Outputs \"Zürich\"\necho $geocoder-\u003egetDescriptionForNumber($swissNumberProto, \"de_DE\");\n\n// Outputs \"Zurigo\"\necho $geocoder-\u003egetDescriptionForNumber($swissNumberProto, \"it_IT\");\n\n// Outputs \"Mountain View, CA\"\necho $geocoder-\u003egetDescriptionForNumber($usNumberProto, \"en_US\");\n\n// Outputs \"Mountain View, CA\"\necho $geocoder-\u003egetDescriptionForNumber($usNumberProto, \"de_DE\");\n\n// Outputs \"미국\" (Korean for United States)\necho $geocoder-\u003egetDescriptionForNumber($usNumberProto, \"ko-KR\");\n\n// Outputs \"Manchester\"\necho $geocoder-\u003egetDescriptionForNumber($gbNumberProto, \"en_GB\");\n\n// Outputs \"영국\" (Korean for United Kingdom)\necho $geocoder-\u003egetDescriptionForNumber($gbNumberProto, \"ko-KR\");\n```\n\n### ShortNumberInfo\n\n```php\n$shortNumberInfo = \\libphonenumber\\ShortNumberInfo::getInstance();\n\n// true\nvar_dump($shortNumberInfo-\u003eisEmergencyNumber(\"999\", \"GB\"));\n\n// true\nvar_dump($shortNumberInfo-\u003econnectsToEmergencyNumber(\"999\", \"GB\"));\n\n// false\nvar_dump($shortNumberInfo-\u003econnectsToEmergencyNumber(\"911\", \"GB\"));\n\n// true\nvar_dump($shortNumberInfo-\u003eisEmergencyNumber(\"911\", \"US\"));\n\n// true\nvar_dump($shortNumberInfo-\u003econnectsToEmergencyNumber(\"911\", \"US\"));\n\n// false\nvar_dump($shortNumberInfo-\u003eisEmergencyNumber(\"911123\", \"US\"));\n\n// true\nvar_dump($shortNumberInfo-\u003econnectsToEmergencyNumber(\"911123\", \"US\"));\n```\n\n### Mapping Phone Numbers to carrier\n\n```php\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\n$swissNumberProto = $phoneUtil-\u003eparse(\"798765432\", \"CH\");\n\n$carrierMapper = \\libphonenumber\\PhoneNumberToCarrierMapper::getInstance();\n// Outputs \"Swisscom\"\necho $carrierMapper-\u003egetNameForNumber($swissNumberProto, \"en\");\n```\n\n### Mapping Phone Numbers to TimeZones\n\n```php\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\n$swissNumberProto = $phoneUtil-\u003eparse(\"798765432\", \"CH\");\n\n$timeZoneMapper = \\libphonenumber\\PhoneNumberToTimeZonesMapper::getInstance();\n// returns array(\"Europe/Zurich\")\n$timeZones = $timeZoneMapper-\u003egetTimeZonesForNumber($swissNumberProto);\n```\n\n## FAQ\n\n#### Problems with Invalid Numbers?\n\nThis 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.\n\nIf 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.\n\nIf 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.\n\n## Generating data\n\nGenerating the data is not normally needed, as this repository will generally always have the up to data metadata.\n\nIf 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\n\n```bash\n$ vendor/bin/phing compile\n```\n\nThis compile process clones the [libphonenumber](https://github.com/googlei18n/libphonenumber) project at the version specified in [METADATA-VERSION.txt](METADATA-VERSION.txt).\n\n## Integration with frameworks\n\nOther packages exist that integrate libphonenumber-for-php into frameworks.\n\n| Framework | Packages      |\n| --------- |:-------------:|\n|Symfony|[PhoneNumberBundle](https://github.com/misd-service-development/phone-number-bundle)|\n|Laravel|[Laravel Phone](https://github.com/Propaganistas/Laravel-Phone)|\n|Yii2|[PhoneInput](https://github.com/Borales/yii2-phone-input)|\n|Kohana|[PhoneNumber](https://github.com/softmediadev/kohana-phonenumber)|\n\nThese packages are supplied by third parties, and their quality can not be guaranteed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelefonica%2Flibphonenumber-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelefonica%2Flibphonenumber-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelefonica%2Flibphonenumber-php/lists"}