{"id":13518830,"url":"https://github.com/giggsey/libphonenumber-for-php","last_synced_at":"2026-02-26T11:18:18.436Z","repository":{"id":7712553,"uuid":"9077725","full_name":"giggsey/libphonenumber-for-php","owner":"giggsey","description":"PHP version of Google's phone number handling library","archived":false,"fork":false,"pushed_at":"2024-10-22T09:23:29.000Z","size":18530,"stargazers_count":4752,"open_issues_count":2,"forks_count":467,"subscribers_count":107,"default_branch":"master","last_synced_at":"2024-10-29T21:01:47.569Z","etag":null,"topics":["hacktoberfest","libphonenumber","phone-number","php"],"latest_commit_sha":null,"homepage":"https://giggsey.com/libphonenumber/","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/giggsey.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":"2013-03-28T13:36:31.000Z","updated_at":"2024-10-29T14:00:26.000Z","dependencies_parsed_at":"2023-02-16T07:01:25.736Z","dependency_job_id":"dac16dcc-3a77-426e-9e7c-b04c1e99b528","html_url":"https://github.com/giggsey/libphonenumber-for-php","commit_stats":{"total_commits":783,"total_committers":65,"mean_commits":"12.046153846153846","dds":"0.27586206896551724","last_synced_commit":"717d328bb7154f439c33136e93da37d614c14432"},"previous_names":[],"tags_count":245,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggsey%2Flibphonenumber-for-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggsey%2Flibphonenumber-for-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggsey%2Flibphonenumber-for-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggsey%2Flibphonenumber-for-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giggsey","download_url":"https://codeload.github.com/giggsey/libphonenumber-for-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222132607,"owners_count":16936614,"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":["hacktoberfest","libphonenumber","phone-number","php"],"created_at":"2024-08-01T05:01:49.605Z","updated_at":"2026-02-23T12:49:19.177Z","avatar_url":"https://github.com/giggsey.png","language":"PHP","funding_links":[],"categories":["PHP","数字","目录","Table of Contents","Text and Numbers","数字 Numbers","Phone Numbers","Numbers","数字( Numbers )"],"sub_categories":["数字 Numbers","Numbers","Components","Globalization","Filtering, Sanitizing and Validation"],"readme":"# 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://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](https://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/google/libphonenumber).\n\n - [Installation](#installation)\n - [Documentation](#documentation)\n - [Online Demo](#online-demo)\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 8.1 to 8.5 are currently 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\ncomposer 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## giggsey/libphonenumber-for-php-lite\n\nIf 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.\n\n### PHP Version Policy\n\nThis library will be updated to use [supported versions of PHP](https://www.php.net/supported-versions.php) without major version bumps.\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## 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/google/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/google/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/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.\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 date metadata.\n\nTo compile the data, run the composer script 'build'\n\n```bash\ncomposer run build\n```\n\nThis build process clones the [libphonenumber](https://github.com/google/libphonenumber) project at the version specified in [METADATA-VERSION.php](METADATA-VERSION.php).\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/odolbeau/phone-number-bundle)|\n|Laravel|[Laravel Phone](https://github.com/Propaganistas/Laravel-Phone)|\n|TYPO3|[TYPO3 Phone Extension](https://github.com/simonschaufi/typo3-phone)|\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%2Fgiggsey%2Flibphonenumber-for-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiggsey%2Flibphonenumber-for-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiggsey%2Flibphonenumber-for-php/lists"}