我正在使用https://github.com/davideme/libphonenumber-for-PHP进行国际电话没有验证。它工作正常,但按照我给出的 github 页面中的指导
"$swissNumberStr = "044 668 18 00";" 和$phoneUtil->parse($swissNumberStr, "CH") ;
作为输入......当我们打电话时
$isValid = $phoneUtil->isValidNumber($swissNumberProto);
它应该返回 true ..因为它是有效的。但对我来说它变得错误了..任何帮助将不胜感激..
演示.php
use com\google\i18n\phonenumbers\PhoneNumberUtil;
use com\google\i18n\phonenumbers\PhoneNumberFormat;
use com\google\i18n\phonenumbers\NumberParseException;
require_once 'PhoneNumberUtil.php';
$swissNumberStr = "044 668 18 00";
$phoneUtil = PhoneNumberUtil::getInstance();
try {
$swissNumberProto = $phoneUtil->parseAndKeepRawInput($swissNumberStr, "CH");
echo $phoneUtil->getNumberType($swissNumberProto);
//var_dump($swissNumberProto);
} catch (NumberParseException $e) {
echo $e;
}
$isValid = $phoneUtil->isValidNumber($swissNumberProto);//return true
var_dump($isValid);
// Produces "+41446681800"
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::INTERNATIONAL) . PHP_EOL;
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::NATIONAL) . PHP_EOL;
echo $phoneUtil->format($swissNumberProto, PhoneNumberFormat::E164) . PHP_EOL;
echo $phoneUtil->formatOutOfCountryCallingNumber($swissNumberProto, "US") . PHP_EOL;