$urls = [
'a' => 'http://localhost:81/test.php?test_param=johi',
'b' => 'http://localhost:81',
'c' => 'http://localhost',
'd' => 'http://localhost:8080',
'e' => 'http://www.xn--e--testjoidiu.jp/',
'f' => 'http://egegbfwork.blagebog10f2.fc2.com/',
'g' => 'http://blogs.yahoo.co.jp/medidgecalg919e',
'h' => 'http://227ebdw.net/kango/1/index.html',
'i' => 'http://gebfa.test-search.net',
];
foreach ($urls as $url) {
$result = preg_match('/(https?:\/\/(www\.)?[0-9a-z\-\.]+:?[0-9]{0,5})/', $url, $matches);
echo $matches[0];
}
// 結果(普通見ないようなドメインもありますが、、、)
a: http://localhost:81
b: http://localhost:81
c: http://localhost
d: http://localhost:8080
e: http://www.xn--e--testjoidiu.jp
f: http://egegbfwork.blagebog10f2.fc2.com
g: http://blogs.yahoo.co.jp
h: http://227ebdw.net
i: http://gebfa.test-search.net