protected function maybeStripExtension(&$number)
{
$matches = array();
$find = preg_match(static::$EXTN_PATTERN, $number, $matches, PREG_OFFSET_CAPTURE);
// If we find a potential extension, and the number preceding this is a viable number, we assume
// it is an extension.
if ($find > 0 && static::isViablePhoneNumber(substr($number, 0, $matches[0][1]))) {
// The numbers are captured into groups in the regular expression.
for ($i = 1, $length = count($matches); $i <= $length; $i++) {
if ($matches[$i][0] != "") {
// We go through the capturing groups until we find one that captured some digits. If none
// did, then we will return the empty string.
$extension = $matches[$i][0];
$number = substr($number, 0, $matches[0][1]);
return $extension;
}
}
}
return "";
}