Skip to content

Commit 1c87c1f

Browse files
committed
Update README
1 parent f4fb428 commit 1c87c1f

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

README.md

+59-8
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ $number->format(PhoneNumberFormat::NATIONAL); // 044 668 18 00
109109
$number->format(PhoneNumberFormat::RFC3966); // tel:+41-44-668-18-00
110110
```
111111

112-
#### Formatting to call from another country
112+
#### Formatting to call from a given country
113113

114114
You may want to present a phone number to an audience in a specific country, with the correct international
115115
prefix when required. This is what `formatForCallingFrom()` does:
@@ -121,7 +121,33 @@ $number->formatForCallingFrom('FR'); // 00 44 7123 456789
121121
$number->formatForCallingFrom('US'); // 011 44 7123 456789
122122
```
123123

124-
### Number types
124+
#### Formatting to call from a mobile phone in a given country
125+
126+
If you want to present a number to dial from a mobile phone, you can use `formatForMobileDialing()`:
127+
128+
```php
129+
$number = PhoneNumber::parse('+447123456789');
130+
131+
$number->formatForMobileDialing('GB', withFormatting: false); // 07123456789
132+
$number->formatForMobileDialing('GB', withFormatting: true); // 07123 456789
133+
134+
$number->formatForMobileDialing('FR', withFormatting: false); // +447123456789
135+
$number->formatForMobileDialing('FR', withFormatting: true); // +44 7123 456789
136+
```
137+
138+
### Getting number information
139+
140+
You can extract basic information from a phone number:
141+
142+
```php
143+
$number = PhoneNumber::parse('+447123456789');
144+
145+
$number->getRegionCode(); // GB
146+
$number->getCountryCode(); // 44
147+
$number->getNationalNumber(); // 7123456789
148+
```
149+
150+
#### Number type
125151

126152
In certain cases, it is possible to know the type of a phone number (fixed line, mobile phone, etc.), using
127153
the `getNumberType()` method, which returns a [PhoneNumberType](https://github.com/brick/phonenumber/blob/master/src/PhoneNumberType.php) enum value:
@@ -134,15 +160,40 @@ PhoneNumber::parse('+33123456789')->getNumberType(); // PhoneNumberType::FIXED_L
134160
If the type is unknown, the `PhoneNumberType::UNKNOWN` value is returned.
135161
Check the `PhoneNumberType` enum for all possible values.
136162

137-
### Number information
163+
#### Description
138164

139-
You can extract the following information from a phone number:
165+
You can get a human-readable description of a phone number:
140166

141167
```php
142-
$number = PhoneNumber::parse('+447123456789');
143-
echo $number->getRegionCode(); // GB
144-
echo $number->getCountryCode(); // 44
145-
echo $number->getNationalNumber(); // 7123456789
168+
PhoneNumber::parse('+33123456789')->getDescription(locale: 'en'); // France
169+
PhoneNumber::parse('+16509030000')->getDescription(locale: 'en'); // Mountain View, CA
170+
```
171+
172+
#### Carrier name
173+
174+
You can get the carrier name for a mobile phone number:
175+
176+
```php
177+
$number = PhoneNumber::parse('+336789012345');
178+
$number->getCarrierName(languageCode: 'en'); // Orange France
179+
```
180+
181+
Note that in countries that support mobile number portability, the carrier name for a phone number may no longer be
182+
correct. You can control whether the carrier name should be returned in this case, by passing a
183+
[CarrierNameMode](https://github.com/brick/phonenumber/blob/master/src/CarrierNameMode.php) enum:
184+
185+
```php
186+
// null, because France supports mobile number portability
187+
$number->getCarrierName(languageCode: 'en', mode: CarrierNameMode::MOBILE_NO_PORTABILITY_ONLY);
188+
```
189+
190+
#### Time zones
191+
192+
You can get the time zones for a phone number:
193+
194+
```php
195+
$number = PhoneNumber::parse('+14155552671');
196+
$number->getTimeZones(); // ['America/Los_Angeles']
146197
```
147198

148199
### Example numbers

0 commit comments

Comments
 (0)