If your users link to some URL, it’s always nice to check if their input actually represents a valid URL. You can do just that with this function:


/**
 * return true if the passed variable is a valid URL address
 * @param $url
 * @return boolean
 */
function isValidURL($url) {
	$pattern  = '/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/';
	return preg_match($pattern, $url);
}

If this function returns true, you might want to actually open the URL (using file_get_contents() or some other function) to see if it works.