FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Just a little Regex problem





imagefree
I am using this regex to validate URLs.


Code:
preg_match('~^(https?|ftps?)://(([a-z0-9-]+\.)+[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(:[0-9]+)?(/?|/\S+)$~ix' , $url)


The problem that is arising is that it doesnt validate urls like

Code:
http://frihost.com?sessid=abcd


Can someone please fix it! If you find other problems in this, please correct.

Also can you please provide a more RFC compliant solution! Thanks.
Hogwarts
Code:
filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED);


Not much point using a regular expression here if filter_var can do it. I can't comment on the speed of both functions, though.
imagefree
Hogwarts wrote:
Code:
filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED);


Not much point using a regular expression here if filter_var can do it. I can't comment on the speed of both functions, though.


This is a simple URL validation, speed doesnt matter. The solution you provided is buggy. I used it earlier. Here is example:

Code:
var_dump( filter_var( 'http://.-frihost..com?sessid=abcd' , FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED ) );

//returns output
//string(33) "http://.-frihost..com?sessid=abcd"
//the URL passes validation test.
Related topics
Fantastico a crash Course
problem with images NOT showing up, plz help...
the best free AV ?
Disk usage problem
Anyone with acne problem
A php problem
Problem with static variable in class
Yet another Heart problem...
Sleep less to get more out of life?
Firefox vs IE
Maths problem
Quadratic forms (Max with constraint)
A new way to control malaria?
I was accused of taking advantage of a woman
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.