eregi()已棄用,需要使用preg_match進行替換。我如何將以下語法轉換爲preg_match?假設以下是URL,它是必需的正則表達式:使用eregi()進行URL驗證,但現在使用preg_match
$url = "https://james.wordpress.com/2013/05/13/my-product-final";
$urlregex = "^(https?|ftp)\:\/\/([a-zåäöÅÄÖæÆøØ0-9+!*(),;?&=\$_.-]+(\:[a-zåäöÅÄÖæÆøØ0-9+!*(),;?&=\$_.-]+)[email protected])?[a-zåäöÅÄÖæÆøØ0-9+\$_-]+(\.[a-zåäöÅÄÖæÆøØ0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-zåäöÅÄÖæÆøØ0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-zåäöÅÄÖæÆøØ0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-zåäöÅÄÖæÆøØ0-9+\$_.-]*)?\$";
下面的代碼工作正常:
if (eregi($urlregex, $url)) {
echo "Valid";
exit;
}
我試圖轉換成 '的preg_match',但它不能正常工作:
if (preg_match("#$urlregex#i", $url)) {
echo "Valid";
exit;
}
也試過像這樣:
if (preg_match('/'.$urlregex.'/i', $url))
這一個工作,但不100%:if(preg_match(「(」。$ urlregex。「)i」,$ url)) – Jerry3456