<?php
function check_url($url_val) {
	$url_pattern = "http\:\/\/[[:alnum:]\-\.]+(\.[[:alpha:]]{2,4})+";
	$url_pattern .= "(\/[\w\-]+)*"; // folders like /val_1/45/
	$url_pattern .= "((\/[\w\-\.]+\.[[:alnum:]]{2,4})?"; // filename like index.html
	$url_pattern .= "|"; // end with filename or ?
	$url_pattern .= "\/?)"; // trailing slash or not
	$error_count = 0;
	if (strpos($url_val, "?")) {
		$url_parts = explode("?", $url_val);
		if (!preg_match("/^".$url_pattern."$/", $url_parts[0])) {
			$error_count++;
		}
		if (!preg_match("/^(&?[\w\-]+=\w*)+$/", $url_parts[1])) {
			$error_count++;
		}
	} else {
		if (!preg_match("/^".$url_pattern."$/", $url_val)) {
			$error_count++;
		}
	}
	if ($error_count > 0) {
		return false;
	} else {
		return true;
	}
}
// voorbeeld
if (check_url("http://www.phphulp.nl/php/scripts/5/249/")) {
    echo "Adres is OK.";
} else {
    echo "Adres is niet geldig";
}
?>