views:

31

answers:

1

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 reproduces: http://maps.google.com/maps?f=q

+1  A: 

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);
Wrikken
awesome! thanks for the quick reply.
ServAce85