1
我需要從文本一堆文本字符串的驗證域名處理如下:如何在PHP中不使用http或https驗證域名?
www.dewalist.com
dewaxxxx.com
ng.dewalist.com
dewaster.com.au
test.co.uk
...
...
我可以用FILTER_VALIDATE_URL然而,這僅驗證完整的URL:http://www.dewalist.com喇嘛喇嘛這是不是我真正想要的東西。
類似像功能,而是用於電子郵件,這對域名:
function extract_email_address ($string)
{
$emails = array();
$string = str_replace("\r\n",' ',$string);
$string = str_replace("\n",' ',$string);
foreach(preg_split('/ /', $string) as $token) {
$email = filter_var($token, FILTER_VALIDATE_EMAIL);
if ($email !== false) {
$emails[] = $email;
}
}
return $emails;
}
[可能的複製](http://stackoverflow.com/questions/2894902/check-for-a-valid-domain-name-in-a-string?rq=1)或[此處](http://stackoverflow.com/questions/10306690/domain-name-validation-with-regex)。 – Mike