當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize方法代碼示例

本文整理匯總了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));
 }
開發者ID:wasabiNorman,項目名稱:libphonenumber-for-php,代碼行數:36,代碼來源:PhoneNumberUtilTest.php


注:本文中的libphonenumber\PhoneNumberUtil::maybeStripInternationalPrefixAndNormalize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。