本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize方法的具體用法?PHP PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize怎麽用?PHP PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libphonenumber\PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testMaybeStripInternationalPrefix
public function testMaybeStripInternationalPrefix()
{
$internationalPrefix = "00[39]";
$numberToStrip = "0034567700-3898003";
// Note the dash is removed as part of the normalization.
$strippedNumber = "45677003898003";
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
$this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of its international prefix.");
// Now the number no longer starts with an IDD prefix, so it should now report
// FROM_DEFAULT_COUNTRY.
$this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
$numberToStrip = "00945677003898003";
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
$this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of its international prefix.");
// Test it works when the international prefix is broken up by spaces.
$numberToStrip = "00 9 45677003898003";
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_IDD, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
$this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of its international prefix.");
// Now the number no longer starts with an IDD prefix, so it should now report
// FROM_DEFAULT_COUNTRY.
$this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
// Test the + symbol is also recognised and stripped.
$numberToStrip = "+45677003898003";
$strippedNumber = "45677003898003";
$this->assertEquals(CountryCodeSource::FROM_NUMBER_WITH_PLUS_SIGN, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
$this->assertEquals($strippedNumber, $numberToStrip, "The number supplied was not stripped of the plus symbol.");
// If the number afterwards is a zero, we should not strip this - no country calling code begins
// with 0.
$numberToStrip = "0090112-3123";
$strippedNumber = "00901123123";
$this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
$this->assertEquals($strippedNumber, $numberToStrip, "The number supplied had a 0 after the match so shouldn't be stripped.");
// Here the 0 is separated by a space from the IDD.
$numberToStrip = "009 0-112-3123";
$this->assertEquals(CountryCodeSource::FROM_DEFAULT_COUNTRY, $this->phoneUtil->maybeStripInternationalPrefixAndNormalize($numberToStrip, $internationalPrefix));
}