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


PHP PhoneNumberUtil::formatOutOfCountryCallingNumber方法代碼示例

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


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

示例1: testLongerNumber

 public function testLongerNumber()
 {
     $number = "12345678901234567";
     $phoneNumber = $this->phoneUtil->parse($number, "DE");
     $this->assertEquals('+4912345678901234567', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::E164));
     $this->assertEquals('+49 12345678901234567', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::INTERNATIONAL));
     $this->assertEquals('12345678901234567', $this->phoneUtil->format($phoneNumber, PhoneNumberFormat::NATIONAL));
     $this->assertEquals('011 49 12345678901234567', $this->phoneUtil->formatOutOfCountryCallingNumber($phoneNumber, 'US'));
     $this->assertEquals('00 49 12345678901234567', $this->phoneUtil->formatOutOfCountryCallingNumber($phoneNumber, 'CH'));
 }
開發者ID:RonLab1987,項目名稱:ride-workshop,代碼行數:10,代碼來源:Issue21Test.php

示例2: testCountryWithNoNumberDesc

 public function testCountryWithNoNumberDesc()
 {
     // Andorra is a country where we don't have PhoneNumberDesc info in the metadata.
     $adNumber = new PhoneNumber();
     $adNumber->setCountryCode(376)->setNationalNumber(12345);
     $this->assertEquals("+376 12345", $this->phoneUtil->format($adNumber, PhoneNumberFormat::INTERNATIONAL));
     $this->assertEquals("+37612345", $this->phoneUtil->format($adNumber, PhoneNumberFormat::E164));
     $this->assertEquals("12345", $this->phoneUtil->format($adNumber, PhoneNumberFormat::NATIONAL));
     $this->assertEquals(PhoneNumberType::UNKNOWN, $this->phoneUtil->getNumberType($adNumber));
     $this->assertTrue($this->phoneUtil->isValidNumber($adNumber));
     // Test dialing a US number from within Andorra.
     $this->assertEquals("00 1 650 253 0000", $this->phoneUtil->formatOutOfCountryCallingNumber(self::$usNumber, RegionCode::AD));
 }
開發者ID:wasabiNorman,項目名稱:libphonenumber-for-php,代碼行數:13,代碼來源:PhoneNumberUtilTest.php

示例3: testFormatOutOfCountryKeepingAlphaChars

 public function testFormatOutOfCountryKeepingAlphaChars()
 {
     $alphaNumericNumber = new PhoneNumber();
     $alphaNumericNumber->setCountryCode(1)->setNationalNumber(8007493524)->setRawInput("1800 six-flag");
     $this->assertEquals("0011 1 800 SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     $alphaNumericNumber->setRawInput("1-800-SIX-flag");
     $this->assertEquals("0011 1 800-SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     $alphaNumericNumber->setRawInput("Call us from UK: 00 1 800 SIX-flag");
     $this->assertEquals("0011 1 800 SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     $alphaNumericNumber->setRawInput("800 SIX-flag");
     $this->assertEquals("0011 1 800 SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     // Formatting from within the NANPA region.
     $this->assertEquals("1 800 SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::US));
     $this->assertEquals("1 800 SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::BS));
     // Testing that if the raw input doesn't exist, it is formatted using
     // formatOutOfCountryCallingNumber.
     $alphaNumericNumber->clearRawInput();
     $this->assertEquals("00 1 800 749 3524", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::DE));
     // Testing AU alpha number formatted from Australia.
     $alphaNumericNumber->setCountryCode(61)->setNationalNumber(827493524)->setRawInput("+61 82749-FLAG");
     // This number should have the national prefix fixed.
     $this->assertEquals("082749-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     $alphaNumericNumber->setRawInput("082749-FLAG");
     $this->assertEquals("082749-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     $alphaNumericNumber->setNationalNumber(18007493524)->setRawInput("1-800-SIX-flag");
     // This number should not have the national prefix prefixed, in accordance with the override for
     // this specific formatting rule.
     $this->assertEquals("1-800-SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AU));
     // The metadata should not be permanently changed, since we copied it before modifying patterns.
     // Here we check this.
     $alphaNumericNumber->setNationalNumber(1800749352);
     $this->assertEquals("1800 749 352", $this->phoneUtil->formatOutOfCountryCallingNumber($alphaNumericNumber, RegionCode::AU));
     // Testing a region with multiple international prefixes.
     $this->assertEquals("+61 1-800-SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::SG));
     // Testing the case of calling from a non-supported region.
     $this->assertEquals("+61 1-800-SIX-FLAG", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AQ));
     // Testing the case with an invalid country calling code.
     $alphaNumericNumber->setCountryCode(0)->setNationalNumber(18007493524)->setRawInput("1-800-SIX-flag");
     // Uses the raw input only.
     $this->assertEquals("1-800-SIX-flag", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::DE));
     // Testing the case of an invalid alpha number.
     $alphaNumericNumber->setCountryCode(1)->setNationalNumber(80749)->setRawInput("180-SIX");
     // No country-code stripping can be done.
     $this->assertEquals("00 1 180-SIX", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::DE));
     // Testing the case of calling from a non-supported region.
     $alphaNumericNumber->setCountryCode(1)->setNationalNumber(80749)->setRawInput("180-SIX");
     // No country-code stripping can be done since the number is invalid.
     $this->assertEquals("+1 180-SIX", $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::AQ));
 }
開發者ID:jpresult,項目名稱:libphonenumber-for-php,代碼行數:49,代碼來源:PhoneNumberUtilTest.php

示例4: callFrom

 /**
  * @param string $country
  *
  * @return string
  */
 public function callFrom(string $country) : string
 {
     return $this->util->formatOutOfCountryCallingNumber($this->number, $country);
 }
開發者ID:cawaphp,項目名稱:cawa,代碼行數:9,代碼來源:PhoneNumber.php

示例5: getOutsideFormat

 /**
  * Getter for the outside format.
  *
  * @access protected
  * @return string
  */
 protected function getOutsideFormat()
 {
     return $this->phoneUtil->formatOutOfCountryCallingNumber($this->parsedResult, $this->getCountryCodeISO3166() === "NL" ? "US" : "NL");
 }
開發者ID:pbmedia,項目名稱:phone,代碼行數:10,代碼來源:Parser.php


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