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


PHP PhoneNumberUtil::formatNumberForMobileDialing方法代碼示例

本文整理匯總了PHP中libphonenumber\PhoneNumberUtil::formatNumberForMobileDialing方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhoneNumberUtil::formatNumberForMobileDialing方法的具體用法?PHP PhoneNumberUtil::formatNumberForMobileDialing怎麽用?PHP PhoneNumberUtil::formatNumberForMobileDialing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在libphonenumber\PhoneNumberUtil的用法示例。


在下文中一共展示了PhoneNumberUtil::formatNumberForMobileDialing方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testFormatNumberForMobileDialing

 public function testFormatNumberForMobileDialing()
 {
     // US toll free numbers are marked as noInternationalDialling in the test metadata for testing
     // purposes.
     $this->assertEquals("800 253 0000", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::US, true));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::CN, true));
     $this->assertEquals("+1 650 253 0000", $this->phoneUtil->formatNumberForMobileDialing(self::$usNumber, RegionCode::US, true));
     $usNumberWithExtn = new PhoneNumber();
     $usNumberWithExtn->mergeFrom(self::$usNumber)->setExtension("1234");
     $this->assertEquals("+1 650 253 0000", $this->phoneUtil->formatNumberForMobileDialing($usNumberWithExtn, RegionCode::US, true));
     $this->assertEquals("8002530000", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::US, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::CN, false));
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing(self::$usNumber, RegionCode::US, false));
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing($usNumberWithExtn, RegionCode::US, false));
     // An invalid US number, which is one digit too long.
     $this->assertEquals("+165025300001", $this->phoneUtil->formatNumberForMobileDialing(self::$usLongNumber, RegionCode::US, false));
     $this->assertEquals("+1 65025300001", $this->phoneUtil->formatNumberForMobileDialing(self::$usLongNumber, RegionCode::US, true));
     // Star numbers. In real life they appear in Israel, but we have them in JP in our test
     // metadata.
     $this->assertEquals("*2345", $this->phoneUtil->formatNumberForMobileDialing(self::$jpStarNumber, RegionCode::JP, false));
     $this->assertEquals("*2345", $this->phoneUtil->formatNumberForMobileDialing(self::$jpStarNumber, RegionCode::JP, true));
     $this->assertEquals("+80012345678", $this->phoneUtil->formatNumberForMobileDialing(self::$internationalTollFree, RegionCode::JP, false));
     $this->assertEquals("+800 1234 5678", $this->phoneUtil->formatNumberForMobileDialing(self::$internationalTollFree, RegionCode::JP, true));
 }
開發者ID:jpresult,項目名稱:libphonenumber-for-php,代碼行數:24,代碼來源:PhoneNumberUtilTest.php

示例2: testFormatNumberForMobileDialing

 public function testFormatNumberForMobileDialing()
 {
     // Numbers are normally dialed in national format in-country, and international format from
     // outside the country.
     $this->assertEquals("030123456", $this->phoneUtil->formatNumberForMobileDialing(self::$deNumber, RegionCode::DE, false));
     $this->assertEquals("+4930123456", $this->phoneUtil->formatNumberForMobileDialing(self::$deNumber, RegionCode::CH, false));
     $this->assertEquals("+4930123456", $this->phoneUtil->formatNumberForMobileDialing(self::$deNumber, RegionCode::CH, false));
     $deNumberWithExtn = new PhoneNumber();
     $deNumberWithExtn->mergeFrom(self::$deNumber)->setExtension("1234");
     $this->assertEquals("030123456", $this->phoneUtil->formatNumberForMobileDialing($deNumberWithExtn, RegionCode::DE, false));
     $this->assertEquals("+4930123456", $this->phoneUtil->formatNumberForMobileDialing($deNumberWithExtn, RegionCode::CH, false));
     // US toll free numbers are marked as noInternationalDialling in the test metadata for testing
     // purposes. For such numbers, we expect nothing to be returned when the region code is not the
     // same one.
     $this->assertEquals("800 253 0000", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::US, true));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::CN, true));
     $this->assertEquals("+1 650 253 0000", $this->phoneUtil->formatNumberForMobileDialing(self::$usNumber, RegionCode::US, true));
     $usNumberWithExtn = new PhoneNumber();
     $usNumberWithExtn->mergeFrom(self::$usNumber)->setExtension("1234");
     $this->assertEquals("+1 650 253 0000", $this->phoneUtil->formatNumberForMobileDialing($usNumberWithExtn, RegionCode::US, true));
     $this->assertEquals("8002530000", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::US, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing(self::$usTollFree, RegionCode::CN, false));
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing(self::$usNumber, RegionCode::US, false));
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing($usNumberWithExtn, RegionCode::US, false));
     // An invalid US number, which is one digit too long.
     $this->assertEquals("+165025300001", $this->phoneUtil->formatNumberForMobileDialing(self::$usLongNumber, RegionCode::US, false));
     $this->assertEquals("+1 65025300001", $this->phoneUtil->formatNumberForMobileDialing(self::$usLongNumber, RegionCode::US, true));
     // Star numbers. In real life they appear in Israel, but we have them in JP in our test
     // metadata.
     $this->assertEquals("*2345", $this->phoneUtil->formatNumberForMobileDialing(self::$jpStarNumber, RegionCode::JP, false));
     $this->assertEquals("*2345", $this->phoneUtil->formatNumberForMobileDialing(self::$jpStarNumber, RegionCode::JP, true));
     $this->assertEquals("+80012345678", $this->phoneUtil->formatNumberForMobileDialing(self::$internationalTollFree, RegionCode::JP, false));
     $this->assertEquals("+800 1234 5678", $this->phoneUtil->formatNumberForMobileDialing(self::$internationalTollFree, RegionCode::JP, true));
     // UAE numbers beginning with 600 (classified as UAN) need to be dialled without +971 locally.
     $this->assertEquals("+971600123456", $this->phoneUtil->formatNumberForMobileDialing(self::$aeUAN, RegionCode::JP, false));
     $this->assertEquals("600123456", $this->phoneUtil->formatNumberForMobileDialing(self::$aeUAN, RegionCode::AE, false));
     $this->assertEquals("+523312345678", $this->phoneUtil->formatNumberForMobileDialing(self::$mxNumber1, RegionCode::MX, false));
     $this->assertEquals("+523312345678", $this->phoneUtil->formatNumberForMobileDialing(self::$mxNumber1, RegionCode::US, false));
     // Non-geographical numbers should always be dialed in international format.
     $this->assertEquals("+80012345678", $this->phoneUtil->formatNumberForMobileDialing(self::$internationalTollFree, RegionCode::US, false));
     $this->assertEquals("+80012345678", $this->phoneUtil->formatNumberForMobileDialing(self::$internationalTollFree, RegionCode::UN001, false));
     // Test that a short number is formatted correctly for mobile dialing within the region,
     // and is not diallable from outside the region.
     $deShortNumber = new PhoneNumber();
     $deShortNumber->setCountryCode(49)->setNationalNumber(123);
     $this->assertEquals("123", $this->phoneUtil->formatNumberForMobileDialing($deShortNumber, RegionCode::DE, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing($deShortNumber, RegionCode::IT, false));
     // Test the special logic for Hungary, where the national prefix must be added before dialing
     // from a mobile phone for regular length numbers, but not for short numbers.
     $huRegularNumber = new PhoneNumber();
     $huRegularNumber->setCountryCode(36)->setNationalNumber(301234567);
     $this->assertEquals("06301234567", $this->phoneUtil->formatNumberForMobileDialing($huRegularNumber, RegionCode::HU, false));
     $this->assertEquals("+36301234567", $this->phoneUtil->formatNumberForMobileDialing($huRegularNumber, RegionCode::JP, false));
     $huShortNumber = new PhoneNumber();
     $huShortNumber->setCountryCode(36)->setNationalNumber(104);
     $this->assertEquals("104", $this->phoneUtil->formatNumberForMobileDialing($huShortNumber, RegionCode::HU, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing($huShortNumber, RegionCode::JP, false));
     // Test the special logic for NANPA countries, for which regular length phone numbers are always
     // output in international format, but short numbers are in national format.
     $usRegularNumber = new PhoneNumber();
     $usRegularNumber->setCountryCode(1)->setNationalNumber(6502530000);
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing($usRegularNumber, RegionCode::US, false));
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing($usRegularNumber, RegionCode::CA, false));
     $this->assertEquals("+16502530000", $this->phoneUtil->formatNumberForMobileDialing($usRegularNumber, RegionCode::BR, false));
     $usShortNumber = new PhoneNumber();
     $usShortNumber->setCountryCode(1)->setNationalNumber(911);
     $this->assertEquals("911", $this->phoneUtil->formatNumberForMobileDialing($usShortNumber, RegionCode::US, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing($usShortNumber, RegionCode::CA, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing($usShortNumber, RegionCode::BR, false));
     // Test that the Australian emergency number 000 is formatted correctly.
     $auNumber = new PhoneNumber();
     $auNumber->setCountryCode(61)->setNationalNumber(0)->setItalianLeadingZero(true)->setNumberOfLeadingZeros(2);
     $this->assertEquals("000", $this->phoneUtil->formatNumberForMobileDialing($auNumber, RegionCode::AU, false));
     $this->assertEquals("", $this->phoneUtil->formatNumberForMobileDialing($auNumber, RegionCode::NZ, false));
 }
開發者ID:wasabiNorman,項目名稱:libphonenumber-for-php,代碼行數:75,代碼來源:PhoneNumberUtilTest.php


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