开发者

How to do a preg_match in php?

I have this argument in php and i want this to just allow users to enter a domain name...i want it so that it doesnt allow characters like "/" "?" and so on...so i only get the domain name such as "http://somedomain.co.nz" or "http://www.somedomain.co.nz"

if(!pr开发者_开发百科eg_match('/^(http):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i',$_POST['story_url']))

Can someone help me add a way i can stop "/" or "?" or anything else to stop from coming on to site...

Thanks

Roshan


Its better to use the function parse_url for this.

if(parse_url(rtrim($POST['story_url'],'/'),PHP_URL_PATH) || 
             parse_url($POST['story_url'], PHP_URL_QUERY)) {
        // invalid...URL has a path or a query string.
} else {
        // valid
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜