0
爲什麼下面的url驗證會給我錯誤。如果我把url = www.google.ca,它給了我一個錯誤的網址。pregmatch不按預期工作
function validateURL($url){
$regex = "((https?|ftp)://)?";
$regex .= "([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)[email protected])?";
$regex .= "([a-z0-9-.]*).([a-z]{2,3})";
$regex .= "(:[0-9]{2,5})?";
$regex .= "(/([a-z0-9+$_-].?)+)*/?";
$regex .= "(?[a-z+&$_.-][a-z0-9;:@&%=+/$_.-]*)?";
$regex .= "(#[a-z_.-][a-z0-9+$_.-]*)?";
if(preg_match('/^$regex$/', $url))
{
echo $url." =".'<font color="blue">Valid URL</font>';
}
else {
echo $url." =".'<font color="red">Invalid URL</font>';
}
}
$url = 'www.google.ca';
validateURL($url);
'如果(的preg_match( 「/^$正則表達式$ /」,$ URL))'...我碰到下面的錯誤,如果我這樣做未知的修飾詞「 /' – Anonymous 2012-03-21 04:18:38
你還沒有逃過反斜槓。 – kba 2012-03-21 04:22:33
.kk我沒有得到逃跑的錯誤了。但你確定驗證的作品,我把'$ url =「wwjw..google.ca」'它說這是有效的 – Anonymous 2012-03-21 04:26:14