File: PhoneNumberMatcher.md

package info (click to toggle)
php-giggsey-libphonenumber 9.0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,492 kB
  • sloc: php: 485,443; sh: 107; makefile: 37
file content (26 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Phone Number Matcher

A class that finds and extracts telephone numbers from text.

## Getting Started
A search instance can be created by using `PhoneNumberUtil::findNumbers()`

### PhoneNumberUtil::findNumbers()

Returns an instance of `PhoneNumberMatcher`, which can be iterated over (returning `PhoneNumberMatch` objects).

It searches the input `$text` for phone numbers, using the `$defaultRegion`. There are also optional parameters to set the phone number `$leniency` (look in [`Leniency`](src/Leniency.php) for possible values), and the `$maxTries` to search for the phone number.

```php
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();

$text = "Hi, can you ring me at 1430 on 0117 496 0123. Thanks!";

$phoneNumberMatcher = $phoneNumberUtil->findNumbers($text, 'GB');

foreach ($phoneNumberMatcher as $phoneNumberMatch) {
    var_dump($phoneNumberMatch->number());
}
// (PhoneNumber) Country Code: 44 National Number: 1174960123
```