On my site I have a place for poeple to put links for downloads. I need to some how validate the url so I don't have people entering in tons of false urls. I also need to validate regular urls. Also the urls need to include the http://
thank you in advance to whomever helps
Regular expressions are your friend 🙂 The best way to go about this would be the following:
if (preg_match('/http:\/\/([A-Za-z-\.]*)\//', $url)) { echo "OK!"; } else { echo "not ok"; }
Hope that helps! If you need any help with the syntax, goto:
http://www.php.net/manual/en/pcre.pattern.syntax.php
Chris King
Here is little code to check if the linked file exists or not. Found on the php.net page.
$fp = @fopen("$url_from_user","r"); if ($fp){ print "The file exists!"; } else { print "The file does not exist"; }
Hope this helps you out.
this is what I used to check sound url:
if (!(ereg("http://[ ]+(.mp3|.rm|.ra|.ram|.wav|.pls|.mpu|.ims|.wma|.m3u)[^ ]*$",$sound_url)) ) { print "<p>Invalid sound url"; }