| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Jan 2006
Posts: 322
![]() ![]() | URL Validation (PHP) I am developing a website that is heavy on domain names, so a good URL validation function is really important. I have searched a lot but haven't been able to find one that seems to work very well. Can anybody help me out? |
| | |
| | #2 (permalink) |
| NamePros Regular Join Date: Jul 2008 Location: Wichita, KS
Posts: 287
![]() ![]() ![]() ![]() | Are you just verifying the URL exists? If so, you can do that by grabbing the headers. Try: PHP Code:
__________________ Free Services: Alertable.com, DetectMobileBrowser.com, DropCart.com, FreeCronJobs.com, HTMLDTD.com, ImagePNG.com, NoCart.com, phpMyLogin.com, RandomTweeps.com, SearchFriendlyURLs.com For Sale: Keyword Domains / Generics See Also:: Google Voice Add-on for Firefox, Google Wave Add-on for Firefox |
| | |
| | #3 (permalink) |
| Senior Member Join Date: Jul 2005 Location: NJ
Posts: 1,219
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | if you're trying to validate that the text input by a user really is a url string, you could do something like filter_var($url, FILTER_VALIDATE_URL); assuming you hvae php5
__________________ Hacksar.com - Your source for random computer tips and tricks! MySiteMemberships.com - Keep track of your site registration information! Like my post? Rep is appreciated! |
| | |
| | #4 (permalink) |
| New Member Join Date: Aug 2009
Posts: 14
![]() | if you have PEAR maybe it works like this PHP Code: |
| | |
| | #5 (permalink) |
| New Member Join Date: Sep 2009
Posts: 4
![]() | function isValidURL($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); } if(!isValidURL($fldbanner_url)) { $errMsg .= "* Please enter valid URL including http://<br>"; }
__________________ Listen to Emails
Last edited by Hanratty; 09-20-2009 at 08:30 AM.
|
| | |