-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
46 lines (40 loc) · 2.38 KB
/
index.php
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;
require_once("./vendor/autoload.php");
$numbers = ["1352120000", "5352120000", "05352120000", "+905352120000", "905352120000", "+395352120000", "+393275506507", "+495352120000",
"+49535120000", "+4953512000011", "0-535-212-00-00", "(535) 212 00 00", "535 212 0000", "+1323232323","53521200", ];
$lib = PhoneNumberUtil::getInstance();
foreach ($numbers as $number) {
$num = $lib->parse($number, "TR");
$countryRegionCode = $lib->getRegionCodeForCountryCode($num->getCountryCode());
$regionMetadata = $lib->getMetadataForRegion($countryRegionCode);
$mobile_code_pattern = $regionMetadata->getMobile()->getNationalNumberPattern();
$matchIsMobile = preg_match("/".$mobile_code_pattern."/", $num->getNationalNumber(), $matches);
echo sprintf("[%s] number country: [%s] with national: %s and int: %s isValid:%b Country: %s isMobile: %b\n",
$number, $num->getCountryCode(), $num->getNationalNumber(), $lib->format($num, PhoneNumberFormat::E164),
(bool)$lib->isValidNumber($num), $countryRegionCode , (bool)$matchIsMobile);
/*
var_export($num);
var_export($countryRegionCode);
var_export($lib->getMetadataForRegion("TR")->hasMobile());
var_export($lib->getMetadataForRegion($lib->getRegionCodeForCountryCode($num->getCountryCode()))->getMobile());
var_export($matchIsMobile);
var_export($matches);
break;
*/
}
/**
* Sample output
[5352120000] number country: [90] with national: 5352120000 and int: +905352120000
[05352120000] number country: [90] with national: 5352120000 and int: +905352120000
[+905352120000] number country: [90] with national: 5352120000 and int: +905352120000
[905352120000] number country: [90] with national: 5352120000 and int: +905352120000
[+395352120000] number country: [39] with national: 5352120000 and int: +395352120000
[+495352120000] number country: [49] with national: 5352120000 and int: +495352120000
[+49535120000] number country: [49] with national: 535120000 and int: +49535120000
[+4953512000011] number country: [49] with national: 53512000011 and int: +4953512000011
[0-535-212-00-00] number country: [90] with national: 5352120000 and int: +905352120000
[(535) 212 00 00] number country: [90] with national: 5352120000 and int: +905352120000
[535 212 0000] number country: [90] with national: 5352120000 and int: +905352120000
*/