: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return '%' . bin2hex($matches[0]);
protected function _normalizeHost($host) {
//Strip username:password
$host = $this->_array_last(explode('@', $host));
if (substr($host, 0, 1) == '[') {
if (strpos($host, ']') === false) { //No closing bracket
$host = preg_replace('/:\d+$/', '', $host);
$u = rawurldecode($host);
if (preg_match('/[\x81-\xff]/', $u)) { //0x80 is technically Unicode, but the GSB canonicalization doesn't consider it one
if (function_exists('idn_to_ascii')) { //Some PHP versions don't have this and we don't have a polyfill
$host = idn_to_ascii($u);
$host = trim($host, '.');
$host = preg_replace('/\.\.+/', '.', $host);
//Canonicalize IP addresses
if ($iphost = $this->_parseIP($host)) {
return strtolower($host);
protected function _parseIP($host) {
// The Windows resolver allows a 4-part dotted decimal IP address to have a
// space followed by any old rubbish, so long as the total length of the
// string doesn't get above 15 characters. So, "10.192.95.89 xy" is
// resolved to 10.192.95.89. If the string length is greater than 15
// characters, e.g. "10.192.95.89 xy.wildcard.example.com", it will be
if (strlen($host) <= 15) {
$host = $this->_array_first(explode(' ', $host));
if (!preg_match('/^((?:0x[0-9a-f]+|[0-9\.])+)$/i', $host)) {
$parts = explode('.', $host);
foreach ($parts as $i => $p) {
if ($i == count($parts) - 1) {
$strings[] = $this->_canonicalNum($p, 5 - count($parts));
$strings[] = $this->_canonicalNum($p, 1);
if ($strings[$i] == '') {
return implode('.', $strings);
protected function _canonicalNum($part, $n) {
if (preg_match('/^0x(\d+)$/i', $part, $matches)) { //hex
$part = hexdec($matches[1]);
else if (preg_match('/^0(\d+)$/i', $part, $matches)) { //octal
$part = octdec($matches[1]);
$strings = array_fill(0, $n, '');
for ($i = $n - 1; $i >= 0; $i--) {
$strings[$i] = (string) ($part & 0xff);
return implode('.', $strings);
protected function _array_first($array) {
protected function _array_last($array) {
return $array[count($array) - 1];