libphonenumber\PhoneNumberUtil::getCountryCodeForRegion PHP Method

getCountryCodeForRegion() public method

Returns the country calling code for a specific region. For example, this would be 1 for the United States, and 64 for New Zealand. Assumes the region is already valid.
public getCountryCodeForRegion ( string $regionCode ) : integer
$regionCode string the region that we want to get the country calling code for
return integer the country calling code for the region denoted by regionCode
    public function getCountryCodeForRegion($regionCode)
    {
        if (!$this->isValidRegionCode($regionCode)) {
            return 0;
        }
        return $this->getCountryCodeForValidRegion($regionCode);
    }

Usage Example

 public function testGetCountryCodeForRegion()
 {
     $this->assertEquals(1, $this->phoneUtil->getCountryCodeForRegion(RegionCode::US));
     $this->assertEquals(64, $this->phoneUtil->getCountryCodeForRegion(RegionCode::NZ));
     $this->assertEquals(0, $this->phoneUtil->getCountryCodeForRegion(null));
     $this->assertEquals(0, $this->phoneUtil->getCountryCodeForRegion(RegionCode::ZZ));
     $this->assertEquals(0, $this->phoneUtil->getCountryCodeForRegion(RegionCode::UN001));
     // CS is already deprecated so the library doesn't support it
     $this->assertEquals(0, $this->phoneUtil->getCountryCodeForRegion(RegionCode::CS));
 }
All Usage Examples Of libphonenumber\PhoneNumberUtil::getCountryCodeForRegion
PhoneNumberUtil