libphonenumber\PhoneNumber::getCountryCode PHP Method

getCountryCode() public method

Returns the country code of this phone number.
public getCountryCode ( ) : integer | null
return integer | null The country code, or null if not set.
    public function getCountryCode()
    {
        return $this->countryCode;
    }

Usage Example

 /**
  * Returns the description of the geographical area the {@code number} corresponds to. This method
  * distinguishes the case of an invalid prefix and a prefix for which the name is not available in
  * the current language. If the description is not available in the current language an empty
  * string is returned. If no description was found for the provided number, null is returned.
  *
  * @internal param \libphonenumber\PhoneNumber $number the phone number to look up
  * @param \libphonenumber\PhoneNumber $phoneNumber
  * @return string|null bla the description of the geographical area
  */
 public function lookup(PhoneNumber $phoneNumber)
 {
     if (count($this->areaCodeMapStorage) == 0) {
         return null;
     }
     $phonePrefix = $phoneNumber->getCountryCode() . $this->phoneUtil->getNationalSignificantNumber($phoneNumber);
     while (strlen($phonePrefix) > 0) {
         if (array_key_exists($phonePrefix, $this->areaCodeMapStorage)) {
             return $this->areaCodeMapStorage[$phonePrefix];
         }
         $phonePrefix = substr($phonePrefix, 0, -1);
     }
     return null;
 }
All Usage Examples Of libphonenumber\PhoneNumber::getCountryCode