This PHP library parses, formats, validates, and analyzes international phone numbers based on Google's libphonenumber metadata. It targets PHP 8.1 through 8.5.
Overview
libphonenumber-for-php wraps the same numbering metadata as Google's Java libphonenumber. You parse strings into PhoneNumber objects, validate numbers for regions, and format them for display or dialing from other countries.
Optional modules cover geocoding, carrier mapping, short-number info, timezone lookup, as-you-type formatting, and number matching in text. A lighter package variant exposes core PhoneNumberUtil only for smaller installs.
Install through Composer; the PECL mbstring extension is required. Versioning tracks Google's releases, and an online demo mirrors behavior for comparison when debugging discrepancies.
Key features
- International phone parsing
- Validation and formatting
- Geocoding helpers
- Carrier and timezone mapping
- As-you-type formatting
- Short number utilities
Use cases
- Validating user phone input
- Formatting numbers for display
- Building SMS or voice flows
- Normalizing CRM contact data
- Detecting numbers in text