$str = 'http://example.com/go/d5863567e7544ae94c5c9342837dbbf8';
$str2 = 'http://www.example.com/go/d5863567e7544ae94c5c9342837dbbf8';
preg_match('/(?<=\/\/).*?(?=\/)/', $str2, $arr);
print_r($arr);
<?php
function extract_host($url)
{
if (preg_match('~^https?://(?:www\.)?([^/]+)~', $url, $m)) {
return $m[1];
}
return null;
}
var_dump(extract_host('http://example.com/go/d5863567e7544ae94c5c9342837dbbf8'));
var_dump(extract_host('http://www.example.com/go/d5863567e7544ae94c5c9342837dbbf8'));
string(11) "example.com"
string(11) "example.com"