当前位置: 首页>>代码示例>>PHP>>正文


PHP PhoneNumber::clearExtension方法代码示例

本文整理汇总了PHP中PhoneNumber::clearExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP PhoneNumber::clearExtension方法的具体用法?PHP PhoneNumber::clearExtension怎么用?PHP PhoneNumber::clearExtension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PhoneNumber的用法示例。


在下文中一共展示了PhoneNumber::clearExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isNumberMatch

 /**
  * Takes two phone numbers and compares them for equality.
  *
  * <p>Returns EXACT_MATCH if the country_code, NSN, presence of a leading zero
  * for Italian numbers and any extension present are the same. Returns NSN_MATCH
  * if either or both has no region specified, and the NSNs and extensions are
  * the same. Returns SHORT_NSN_MATCH if either or both has no region specified,
  * or the region specified is the same, and one NSN could be a shorter version
  * of the other number. This includes the case where one has an extension
  * specified, and the other does not. Returns NO_MATCH otherwise. For example,
  * the numbers +1 345 657 1234 and 657 1234 are a SHORT_NSN_MATCH. The numbers
  * +1 345 657 1234 and 345 657 are a NO_MATCH.
  *
  * @param $firstNumberIn PhoneNumber|string First number to compare. If it is a
  * string it can contain formatting, and can have country calling code specified
  * with + at the start.
  * @param $secondNumberIn PhoneNumber|string Second number to compare. If it is a
  * string it can contain formatting, and can have country calling code specified
  * with + at the start.
  * @throws \InvalidArgumentException
  * @return int {MatchType} NOT_A_NUMBER, NO_MATCH,
  */
 public function isNumberMatch($firstNumberIn, $secondNumberIn)
 {
     if (is_string($firstNumberIn) && is_string($secondNumberIn)) {
         try {
             $firstNumberAsProto = $this->parse($firstNumberIn, self::UNKNOWN_REGION);
             return $this->isNumberMatch($firstNumberAsProto, $secondNumberIn);
         } catch (NumberParseException $e) {
             if ($e->getErrorType() === NumberParseException::INVALID_COUNTRY_CODE) {
                 try {
                     $secondNumberAsProto = $this->parse($secondNumberIn, self::UNKNOWN_REGION);
                     return $this->isNumberMatch($secondNumberAsProto, $firstNumberIn);
                 } catch (NumberParseException $e2) {
                     if ($e2->getErrorType() === NumberParseException::INVALID_COUNTRY_CODE) {
                         try {
                             $firstNumberProto = new PhoneNumber();
                             $secondNumberProto = new PhoneNumber();
                             $this->parseHelper($firstNumberIn, null, false, false, $firstNumberProto);
                             $this->parseHelper($secondNumberIn, null, false, false, $secondNumberProto);
                             return $this->isNumberMatch($firstNumberProto, $secondNumberProto);
                         } catch (NumberParseException $e3) {
                             // Fall through and return MatchType::NOT_A_NUMBER
                         }
                     }
                 }
             }
         }
         return MatchType::NOT_A_NUMBER;
     }
     if ($firstNumberIn instanceof PhoneNumber && is_string($secondNumberIn)) {
         // First see if the second number has an implicit country calling code, by attempting to parse
         // it.
         try {
             $secondNumberAsProto = $this->parse($secondNumberIn, self::UNKNOWN_REGION);
             return $this->isNumberMatch($firstNumberIn, $secondNumberAsProto);
         } catch (NumberParseException $e) {
             if ($e->getErrorType() === NumberParseException::INVALID_COUNTRY_CODE) {
                 // The second number has no country calling code. EXACT_MATCH is no longer possible.
                 // We parse it as if the region was the same as that for the first number, and if
                 // EXACT_MATCH is returned, we replace this with NSN_MATCH.
                 $firstNumberRegion = $this->getRegionCodeForCountryCode($firstNumberIn->getCountryCode());
                 try {
                     if ($firstNumberRegion != self::UNKNOWN_REGION) {
                         $secondNumberWithFirstNumberRegion = $this->parse($secondNumberIn, $firstNumberRegion);
                         $match = $this->isNumberMatch($firstNumberIn, $secondNumberWithFirstNumberRegion);
                         if ($match === MatchType::EXACT_MATCH) {
                             return MatchType::NSN_MATCH;
                         }
                         return $match;
                     } else {
                         // If the first number didn't have a valid country calling code, then we parse the
                         // second number without one as well.
                         $secondNumberProto = new PhoneNumber();
                         $this->parseHelper($secondNumberIn, null, false, false, $secondNumberProto);
                         return $this->isNumberMatch($firstNumberIn, $secondNumberProto);
                     }
                 } catch (NumberParseException $e2) {
                     // Fall-through to return NOT_A_NUMBER.
                 }
             }
         }
     }
     if ($firstNumberIn instanceof PhoneNumber && $secondNumberIn instanceof PhoneNumber) {
         // Make copies of the phone number so that the numbers passed in are not edited.
         $firstNumber = new PhoneNumber();
         $firstNumber->mergeFrom($firstNumberIn);
         $secondNumber = new PhoneNumber();
         $secondNumber->mergeFrom($secondNumberIn);
         // First clear raw_input, country_code_source and preferred_domestic_carrier_code fields and any
         // empty-string extensions so that we can use the proto-buffer equality method.
         $firstNumber->clearRawInput();
         $firstNumber->clearCountryCodeSource();
         $firstNumber->clearPreferredDomesticCarrierCode();
         $secondNumber->clearRawInput();
         $secondNumber->clearCountryCodeSource();
         $secondNumber->clearPreferredDomesticCarrierCode();
         if ($firstNumber->hasExtension() && mb_strlen($firstNumber->getExtension()) === 0) {
             $firstNumber->clearExtension();
         }
//.........这里部分代码省略.........
开发者ID:kasirye,项目名称:faveo-helpdesk,代码行数:101,代码来源:PhoneNumberUtil.php

示例2: getLengthOfNationalDestinationCode

 /**
  * Gets the length of the national destination code (NDC) from the PhoneNumber object passed in,
  * so that clients could use it to split a national significant number into NDC and subscriber
  * number. The NDC of a phone number is normally the first group of digit(s) right after the
  * country calling code when the number is formatted in the international format, if there is a
  * subscriber number part that follows. An example of how this could be used:
  *
  * <pre>
  * PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
  * PhoneNumber number = phoneUtil.parse("18002530000", "US");
  * String nationalSignificantNumber = phoneUtil.getNationalSignificantNumber(number);
  * String nationalDestinationCode;
  * String subscriberNumber;
  *
  * int nationalDestinationCodeLength = phoneUtil.getLengthOfNationalDestinationCode(number);
  * if (nationalDestinationCodeLength > 0) {
  *   nationalDestinationCode = nationalSignificantNumber.substring(0,
  *	   nationalDestinationCodeLength);
  *   subscriberNumber = nationalSignificantNumber.substring(nationalDestinationCodeLength);
  * } else {
  *   nationalDestinationCode = "";
  *   subscriberNumber = nationalSignificantNumber;
  * }
  * </pre>
  *
  * Refer to the unittests to see the difference between this function and
  * {@link #getLengthOfGeographicalAreaCode}.
  *
  * @param \libphonenumber\PhoneNumber $number the PhoneNumber object for which clients want to know the length of the NDC.
  * @return int the length of NDC of the PhoneNumber object passed in.
  */
 public function getLengthOfNationalDestinationCode(PhoneNumber $number)
 {
     if ($number->hasExtension()) {
         // We don't want to alter the proto given to us, but we don't want to include the extension
         // when we format it, so we copy it and clear the extension here.
         $copiedProto = new PhoneNumber();
         $copiedProto->mergeFrom($number);
         $copiedProto->clearExtension();
     } else {
         $copiedProto = clone $number;
     }
     $nationalSignificantNumber = $this->format($copiedProto, PhoneNumberFormat::INTERNATIONAL);
     $numberGroups = preg_split('/' . self::NON_DIGITS_PATTERN . '/', $nationalSignificantNumber);
     // The pattern will start with "+COUNTRY_CODE " so the first group will always be the empty
     // string (before the + symbol) and the second group will be the country calling code. The third
     // group will be area code if it is not the last group.
     if (count($numberGroups) <= 3) {
         return 0;
     }
     if ($this->getRegionCodeForCountryCode($number->getCountryCode()) === "AR" && $this->getNumberType($number) == PhoneNumberType::MOBILE) {
         // Argentinian mobile numbers, when formatted in the international format, are in the form of
         // +54 9 NDC XXXX.... As a result, we take the length of the third group (NDC) and add 1 for
         // the digit 9, which also forms part of the national significant number.
         // TODO: Investigate the possibility of better modeling the metadata to make it
         // easier to obtain the NDC.
         return strlen($numberGroups[3]) + 1;
     }
     return strlen($numberGroups[2]);
 }
开发者ID:jpresult,项目名称:libphonenumber-for-php,代码行数:60,代码来源:PhoneNumberUtil.php


注:本文中的PhoneNumber::clearExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。