[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8356":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":22,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":28,"readmeContent":29,"aiSummary":30,"trendingCount":16,"starSnapshotCount":16,"syncStatus":15,"lastSyncTime":31,"discoverSource":32},8356,"libphonenumber-for-php","giggsey\u002Flibphonenumber-for-php","giggsey","PHP version of Google's phone number handling library","https:\u002F\u002Fgiggsey.com\u002Flibphonenumber\u002F",null,"PHP",5031,479,105,2,0,8,39.04,"Apache License 2.0",false,"master",true,[24,25,26,27],"hacktoberfest","libphonenumber","phone-number","php","2026-06-12 02:01:52","# libphonenumber for PHP [![Build Status](https:\u002F\u002Fgithub.com\u002Fgiggsey\u002Flibphonenumber-for-php\u002Fworkflows\u002FContinuous%20Integration\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fgiggsey\u002Flibphonenumber-for-php\u002Factions?query=workflow%3A%22Continuous+Integration%22) [![Coverage Status](https:\u002F\u002Fimg.shields.io\u002Fcoveralls\u002Fgiggsey\u002Flibphonenumber-for-php.svg?style=flat-square)](https:\u002F\u002Fcoveralls.io\u002Fr\u002Fgiggsey\u002Flibphonenumber-for-php?branch=master)\n\n[![Total Downloads](https:\u002F\u002Fposer.pugx.org\u002Fgiggsey\u002Flibphonenumber-for-php\u002Fdownloads?format=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fgiggsey\u002Flibphonenumber-for-php)\n[![Downloads per month](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fdm\u002Fgiggsey\u002Flibphonenumber-for-php.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fgiggsey\u002Flibphonenumber-for-php)\n[![Latest Stable Version](https:\u002F\u002Fimg.shields.io\u002Fpackagist\u002Fv\u002Fgiggsey\u002Flibphonenumber-for-php.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fgiggsey\u002Flibphonenumber-for-php)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-Apache%202.0-red.svg?style=flat-square)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fgiggsey\u002Flibphonenumber-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:\u002F\u002Fgithub.com\u002Fgoogle\u002Flibphonenumber).\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:\u002F\u002Fphp.net\u002Fmbstring) extension is required.\n\nIt is recommended to use [composer](https:\u002F\u002Fgetcomposer.org) to install the library.\n\n```bash\ncomposer require giggsey\u002Flibphonenumber-for-php\n```\n\nYou can also use any other [PSR-4](http:\u002F\u002Fwww.php-fig.org\u002Fpsr\u002Fpsr-4\u002F) compliant autoloader.\n\nIf you do not use composer, ensure that you also load any dependencies that this project has, such as [giggsey\u002Flocale](https:\u002F\u002Fgithub.com\u002Fgiggsey\u002FLocale).\n\n## giggsey\u002Flibphonenumber-for-php-lite\n\nIf you only want to make use of the core PhoneNumber Util functionality, you can use [giggsey\u002Flibphonenumber-for-php-lite](https:\u002F\u002Fgithub.com\u002Fgiggsey\u002Flibphonenumber-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:\u002F\u002Fwww.php.net\u002Fsupported-versions.php) without major version bumps.\n\n## Documentation\n\n - [PhoneNumber Util](docs\u002FPhoneNumberUtil.md)\n - [ShortNumber Info](docs\u002FShortNumberInfo.md)\n - [Phone Number Geolocation](docs\u002FPhoneNumberOfflineGeocoder.md)\n - [Phone Number to Carrier Mapping](docs\u002FPhoneNumberToCarrierMapper.md)\n - [Phone Number to Timezone Mapping](docs\u002FPhoneNumberToTimeZonesMapper.md)\n - [Phone Number Matcher](docs\u002FPhoneNumberMatcher.md)\n - [As You Type Formatter](docs\u002FAsYouTypeFormatter.md)\n\n## Online Demo\nAn [online demo](http:\u002F\u002Fgiggsey.com\u002Flibphonenumber\u002F) is available, and the source can be found at [giggsey\u002Flibphonenumber-example](https:\u002F\u002Fgithub.com\u002Fgiggsey\u002Flibphonenumber-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:\u002F\u002Fsemver.org\u002F), 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:\u002F\u002Fgithub.com\u002Fgoogle\u002Flibphonenumber#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\u002Fnormalize it into a PhoneNumber object:\n\n```php\n$swissNumberStr = \"044 668 18 00\";\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\ntry {\n    $swissNumberProto = $phoneUtil->parse($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 =>\n      int(41)\n     private $nationalNumber =>\n      double(446681800)\n     private $extension =>\n      NULL\n     private $italianLeadingZero =>\n      NULL\n     private $rawInput =>\n      NULL\n     private $countryCodeSource =>\n      NULL\n     private $preferredDomesticCarrierCode =>\n      NULL\n    }\n\nNow let us validate whether the number is valid:\n\n```php\n$isValid = $phoneUtil->isValidNumber($swissNumberProto);\nvar_dump($isValid); \u002F\u002F true\n```\n\nThere are a few formats supported by the formatting method, as illustrated below:\n\n```php\n\u002F\u002F Produces \"+41446681800\"\necho $phoneUtil->format($swissNumberProto, \\libphonenumber\\PhoneNumberFormat::E164);\n\n\u002F\u002F Produces \"044 668 18 00\"\necho $phoneUtil->format($swissNumberProto, \\libphonenumber\\PhoneNumberFormat::NATIONAL);\n\n\u002F\u002F Produces \"+41 44 668 18 00\"\necho $phoneUtil->format($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\u002F\u002F Produces \"011 41 44 668 1800\", the number when it is dialled in the United States.\necho $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, \"US\");\n\n\u002F\u002F Produces \"00 41 44 668 18 00\", the number when it is dialled in Great Britain.\necho $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, \"GB\");\n```\n\n### Geocoder\n\n```php\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\n\n$swissNumberProto = $phoneUtil->parse(\"044 668 18 00\", \"CH\");\n$usNumberProto = $phoneUtil->parse(\"+1 650 253 0000\", \"US\");\n$gbNumberProto = $phoneUtil->parse(\"0161 496 0000\", \"GB\");\n\n$geocoder = \\libphonenumber\\geocoding\\PhoneNumberOfflineGeocoder::getInstance();\n\n\u002F\u002F Outputs \"Zurich\"\necho $geocoder->getDescriptionForNumber($swissNumberProto, \"en_US\");\n\n\u002F\u002F Outputs \"Zürich\"\necho $geocoder->getDescriptionForNumber($swissNumberProto, \"de_DE\");\n\n\u002F\u002F Outputs \"Zurigo\"\necho $geocoder->getDescriptionForNumber($swissNumberProto, \"it_IT\");\n\n\u002F\u002F Outputs \"Mountain View, CA\"\necho $geocoder->getDescriptionForNumber($usNumberProto, \"en_US\");\n\n\u002F\u002F Outputs \"Mountain View, CA\"\necho $geocoder->getDescriptionForNumber($usNumberProto, \"de_DE\");\n\n\u002F\u002F Outputs \"미국\" (Korean for United States)\necho $geocoder->getDescriptionForNumber($usNumberProto, \"ko-KR\");\n\n\u002F\u002F Outputs \"Manchester\"\necho $geocoder->getDescriptionForNumber($gbNumberProto, \"en_GB\");\n\n\u002F\u002F Outputs \"영국\" (Korean for United Kingdom)\necho $geocoder->getDescriptionForNumber($gbNumberProto, \"ko-KR\");\n```\n\n### ShortNumberInfo\n\n```php\n$shortNumberInfo = \\libphonenumber\\ShortNumberInfo::getInstance();\n\n\u002F\u002F true\nvar_dump($shortNumberInfo->isEmergencyNumber(\"999\", \"GB\"));\n\n\u002F\u002F true\nvar_dump($shortNumberInfo->connectsToEmergencyNumber(\"999\", \"GB\"));\n\n\u002F\u002F false\nvar_dump($shortNumberInfo->connectsToEmergencyNumber(\"911\", \"GB\"));\n\n\u002F\u002F true\nvar_dump($shortNumberInfo->isEmergencyNumber(\"911\", \"US\"));\n\n\u002F\u002F true\nvar_dump($shortNumberInfo->connectsToEmergencyNumber(\"911\", \"US\"));\n\n\u002F\u002F false\nvar_dump($shortNumberInfo->isEmergencyNumber(\"911123\", \"US\"));\n\n\u002F\u002F true\nvar_dump($shortNumberInfo->connectsToEmergencyNumber(\"911123\", \"US\"));\n```\n\n### Mapping Phone Numbers to carrier\n\n```php\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\n$swissNumberProto = $phoneUtil->parse(\"798765432\", \"CH\");\n\n$carrierMapper = \\libphonenumber\\PhoneNumberToCarrierMapper::getInstance();\n\u002F\u002F Outputs \"Swisscom\"\necho $carrierMapper->getNameForNumber($swissNumberProto, \"en\");\n```\n\n### Mapping Phone Numbers to TimeZones\n\n```php\n$phoneUtil = \\libphonenumber\\PhoneNumberUtil::getInstance();\n$swissNumberProto = $phoneUtil->parse(\"798765432\", \"CH\");\n\n$timeZoneMapper = \\libphonenumber\\PhoneNumberToTimeZonesMapper::getInstance();\n\u002F\u002F returns array(\"Europe\u002FZurich\")\n$timeZones = $timeZoneMapper->getTimeZonesForNumber($swissNumberProto);\n```\n\n## FAQ\n\n#### Problems with Invalid Numbers?\n\nThis library uses phone number metadata from Google's [libphonenumber](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Flibphonenumber). 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:\u002F\u002Fgithub.com\u002Fgoogle\u002Flibphonenumber) via their [Online Demo](https:\u002F\u002Flibphonenumber.appspot.com\u002F). 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:\u002F\u002Flibphonenumber.appspot.com\u002F) gives a different result to the [libphonenumber-for-php demo](http:\u002F\u002Fgiggsey.com\u002Flibphonenumber\u002F), 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:\u002F\u002Fgithub.com\u002Fgoogle\u002Flibphonenumber) 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:\u002F\u002Fgithub.com\u002Fodolbeau\u002Fphone-number-bundle)|\n|Laravel|[Laravel Phone](https:\u002F\u002Fgithub.com\u002FPropaganistas\u002FLaravel-Phone)|\n|TYPO3|[TYPO3 Phone Extension](https:\u002F\u002Fgithub.com\u002Fsimonschaufi\u002Ftypo3-phone)|\n\nThese packages are supplied by third parties, and their quality can not be guaranteed.\n","giggsey\u002Flibphonenumber-for-php 是一个用于解析、格式化、存储和验证国际电话号码的 PHP 库。该项目基于 Google 的 libphonenumber，提供了丰富的功能，如电话号码地理编码、短号信息处理以及将电话号码映射到运营商或时区等。该库支持 PHP 8.1 至 8.5 版本，并且需要 mbstring 扩展。它非常适合在需要处理多国电话号码的应用场景中使用，例如电子商务平台、客户关系管理系统或任何涉及跨国通信的服务。通过 Composer 可以方便地安装此库，同时也提供了轻量级版本以满足不同需求。","2026-06-11 03:17:30","top_language"]