protected function buildNationalNumberForParsing($numberToParse, &$nationalNumber)
{
$indexOfPhoneContext = strpos($numberToParse, static::RFC3966_PHONE_CONTEXT);
if ($indexOfPhoneContext > 0) {
$phoneContextStart = $indexOfPhoneContext + mb_strlen(static::RFC3966_PHONE_CONTEXT);
// If the phone context contains a phone number prefix, we need to capture it, whereas domains
// will be ignored.
if (substr($numberToParse, $phoneContextStart, 1) == static::PLUS_SIGN) {
// Additional parameters might follow the phone context. If so, we will remove them here
// because the parameters after phone context are not important for parsing the
// phone number.
$phoneContextEnd = strpos($numberToParse, ';', $phoneContextStart);
if ($phoneContextEnd > 0) {
$nationalNumber .= substr($numberToParse, $phoneContextStart, $phoneContextEnd - $phoneContextStart);
} else {
$nationalNumber .= substr($numberToParse, $phoneContextStart);
}
}
// Now append everything between the "tel:" prefix and the phone-context. This should include
// the national number, an optional extension or isdn-subaddress component. Note we also
// handle the case when "tel:" is missing, as we have seen in some of the phone number inputs.
// In that case, we append everything from the beginning.
$indexOfRfc3966Prefix = strpos($numberToParse, static::RFC3966_PREFIX);
$indexOfNationalNumber = $indexOfRfc3966Prefix !== false ? $indexOfRfc3966Prefix + strlen(static::RFC3966_PREFIX) : 0;
$nationalNumber .= substr($numberToParse, $indexOfNationalNumber, $indexOfPhoneContext - $indexOfNationalNumber);
} else {
// Extract a possible number from the string passed in (this strips leading characters that
// could not be the start of a phone number.)
$nationalNumber .= static::extractPossibleNumber($numberToParse);
}
// Delete the isdn-subaddress and everything after it if it is present. Note extension won't
// appear at the same time with isdn-subaddress according to paragraph 5.3 of the RFC3966 spec,
$indexOfIsdn = strpos($nationalNumber, static::RFC3966_ISDN_SUBADDRESS);
if ($indexOfIsdn > 0) {
$nationalNumber = substr($nationalNumber, 0, $indexOfIsdn);
}
// If both phone context and isdn-subaddress are absent but other parameters are present, the
// parameters are left in nationalNumber. This is because we are concerned about deleting
// content from a potential number string when there is no strong evidence that the number is
// actually written in RFC3966.
}