开发者

Asterisk in eregi

//URL START
$urlregex = "^开发者_JS百科(https?|ftp)\:\/\/";
// USER AND PASS
$urlregex .= "([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?";
// HOSTNAME OR IP
$urlregex .= "[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*";
// PORT
$urlregex .= "(\:[0-9]{2,5})?";
// PATH
$urlregex .= "(\/([a-z0-9+\$_-]\.?)+)*\/?";
// GET Query
$urlregex .= "(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?";
// ANCHOR
$urlregex .= "(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
// check
if (eregi($urlregex, $url)) {echo "good";} else {echo "bad";}

but what if I have http://www.example.com/about-me/my-4*-hotel/

That eregi check isn't valid because of the asterisk. What should I do?


From the documentation:

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

Use filter_var with FILTER_VALIDATE_URL instead. Or if you insist on using regular expression then use preg_*.


I think your problem is in the URL, not the regex. Last time I checked, asterisk was not permitted in the path portion of a URL. If you really need an asterisk there you should escape it:

http://www.example.com/about-me/my-4%2A-hotel/


You could change your regex to allow stars...

$urlregex .= "(\/([a-z0-9+\$_*-].?)+)*\/?"; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜