public function numberToE164($number = '', $countryCode = null)
 {
     if ($number == '') {
         $phoneNumber = new PhoneNumber();
         $phoneNumber->setCountryCode($countryCode);
         return $phoneNumber;
     }
     // extract the country code from the number if possible
     // get all possibilities
     $possibleCountryCodes = $this->getAllPossibleCountryCodes($countryCode, $number);
     //the original match order matters also
     //if the weights are the same
     foreach ($possibleCountryCodes as $k => $numberCode) {
         $possibleCountryCodes[$k]['order'] = $k;
     }
     $foundValidNumbers = array();
     $foundInvalidNumbers = array();
     //re-order the country codes based on the suplied weights
     uasort($possibleCountryCodes, array($this, 'comparePossibleNumbers'));
     $possibleCountryCodes = array_values($possibleCountryCodes);
     if (empty($possibleCountryCodes)) {
         //return default number
         $phoneNumber = new PhoneNumber();
         $phoneNumber->setCountryCode($countryCode);
         $phoneNumber->setSubscriberNumber($number);
         return $phoneNumber;
     }
     foreach ($possibleCountryCodes as $k => $numberCode) {
         $countryCode = $numberCode['countryCode'];
         $subscriberNumber = $numberCode['subscriberNumber'];
         // cleanup the non-numeric chars
         $subscriberNumber = preg_replace('/[^0-9]+/', '', $subscriberNumber);
         // easier to read than 65 / 60 / etc
         $regionCode = $this->getRegionCodeFromCountryCode($countryCode);
         $regionFormatter = $this->getRegionFormatter($regionCode);
         if (!$regionFormatter) {
             // since we have no specific algorithm for this country
             // assume it's correct
             $phoneNumber = new PhoneNumber();
             $phoneNumber->setCountryCode($countryCode);
             $phoneNumber->setIsValid(true);
             $phoneNumber->setSubscriberNumber($subscriberNumber);
             $this->addListNumber($foundValidNumbers, $phoneNumber);
             continue;
         }
         //extract area code
         $phoneNumber = $regionFormatter->extractNationalDestinationCode($subscriberNumber, $countryCode);
         if (!$phoneNumber) {
             $phoneNumber = new PhoneNumber();
             $phoneNumber->setCountryCode($countryCode);
             $phoneNumber->setSubscriberNumber($subscriberNumber);
             $this->addListNumber($foundInvalidNumbers, $phoneNumber);
         } else {
             $phoneNumber->setCountryCode($countryCode);
             $phoneNumber->setIsValid(true);
             $this->addListNumber($foundValidNumbers, $phoneNumber);
         }
     }
     foreach ($foundValidNumbers as $countryCode => $numbers) {
         foreach ($numbers as $phoneNumber) {
             return $phoneNumber;
         }
     }
     foreach ($foundInvalidNumbers as $countryCode => $numbers) {
         foreach ($numbers as $phoneNumber) {
             return $phoneNumber;
         }
     }
 }