eregi() 已弃用,需要替换为 preg_match。如何将以下语法转换为 preg_match?假设以下是 url 并且它是必需的正则表达式模式:
$url = "https://james.wordpress.com/2013/05/13/my-product-final";
$urlregex = "^(https?|ftp)\:\/\/([a-zåäöÅÄÖæÆøØ0-9+!*(),;?&=\$_.-]+(\:[a-zåäöÅÄÖæÆøØ0-9+!*(),;?&=\$_.-]+)?@)?[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))