Mini-PHP regex: globbing valid URLs.

This is amazingly primitive, and simple – but it’s something I needed to write. My URL redirect needs to be semi-sentient, in that it needs to understand if users are entering a full URL such as ‘http://www.google.com/’ or merely ‘www.google.com’. This simple little code snippit checks for the validity of the URL given, and if it doesn’t match, assumes it is a standard web redirect:

if (!(preg_match(”/^(http|ftp|https)/”, $ret))) $ret = “http://$ret”;

I said it was rather simple! :)