tiki Posted June 27, 2006 Share Posted June 27, 2006 This is supposed to check if the website is valid and has http://.If it does not match it echos an error, but it doesnt seem to work correctly.[code]<?phpif (!eregi("^((http|https|ftp)://)?([[:alnum:]-])+(\.)([[:alnum:]]){2,4}([[:alnum:]/+=%&_.~?-]*)$", stripslashes(trim($_POST["website"])))) {?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/ Share on other sites More sharing options...
tiki Posted July 5, 2006 Author Share Posted July 5, 2006 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/#findComment-53245 Share on other sites More sharing options...
effigy Posted July 5, 2006 Share Posted July 5, 2006 Which part isn't working correctly? Did you get any error messages from PHP? Is it allowing invalid data? Is it allowing [i]valid[/i] data? Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/#findComment-53326 Share on other sites More sharing options...
Wildbug Posted July 5, 2006 Share Posted July 5, 2006 [quote author=tiki link=topic=96937.msg391830#msg391830 date=1152093830]Anyone?[/quote]Well, I'm mostly acquainted with Perl's regular expressions, but it looks like you're trying to match a possible URI followed by some alphanumeric characters (or dashes) followed by a dot followed by 2-4 more alphanumeric characters, then any number of alphanumeric characters plus plenty of symbols, am I right?So something like "http://phpfreaks.com/" would match while "www.phpfreaks.com" would not. Nor would an IP address, "http://66.97.171.5/forums/index.php"I don't think your regular expression is very robust in terms of encompassing all possible valid forms of website addresses.You might also consider using one of PHP's filesystem functions or network functions to attempt to access the page the user has specified in order to confirm its existence. I don't know if that would work all the time, but it's a thought. Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/#findComment-53329 Share on other sites More sharing options...
tiki Posted July 14, 2006 Author Share Posted July 14, 2006 It allows it through when it does not have a http:// on the front of it, shouldnt this make it so it doesnt pass unless its there? Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/#findComment-58111 Share on other sites More sharing options...
effigy Posted July 14, 2006 Share Posted July 14, 2006 Change ^((http|https|ftp)://)? to ^(https?|ftp):// Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/#findComment-58116 Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 your pattern uses the ? quantifier after the optional http|https|ftp set. '?' specifies EITHER 0 or 1 instances of the sub-pattern, so a string with 0 instances of that sub-pattern will be allowed through.you'll want the 1 or more quantifier, which i can't remember off the top of my head. have a look in the php manual at syntax.[b]EDIT: or do what effigy said.[/b] Quote Link to comment https://forums.phpfreaks.com/topic/13000-checking-if-correct-url/#findComment-58118 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.