开发者

Regular Expression to Validate Long URLs in PHP

开发者 https://www.devze.com 2023-01-08 07:36 出处:网络
I am looking for help in creating a Regular Expression that validates a URL of very long length (eg. a very long Google Maps address).I am new to regular expressions and I am using it in PHP with preg

I am looking for help in creating a Regular Expression that validates a URL of very long length (eg. a very long Google Maps address). I am new to regular expressions and I am using it in PHP with preg_match().

I have used the expression:

preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)

but this doesn't work for the very long URLs. My knowledge of Regular Expressions is virtually non-existent, so if there's a simple change that would help, feel free to point it out.

Here's an example of the errors that I'm receiving:

If the link is originally: http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=park&sll=43.882057,-108.852539&sspn=4.204424,9.876709&ie=UTF8&hq=park&hnear=&z=7

Validation repro开发者_运维百科duces: http://maps.google.com/maps?f=q


Validating whether it's a valid url:

 $valid = filter_var($url, FILTER_VALIDATE_URL);

Inspecting whether required get variables are set, just get them as an associative array and use isset():

 parse_str(parse_url($url,PHP_URL_QUERY),$get_variables);
0

精彩评论

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