i tried it, but in my case it doesnt work. i need it also accept links with variables after /,
like - http://abc.com/?id=12&cat=2#12
your mentioned script says,
NO!, http://abc.com/?id=12&cat=2#12 is NOT a valid url
how to improve that script?
function is_valid_url($url) {
$pattern = "#^(http:\/\/|https:\/\/|www\.)(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?(\/)*$#i";
if (!preg_match($pattern, $url)) {
return false;
} else {
return true;
}
} // is_valid_url()
$str = '//example.com';
if (is_valid_url($str)) {
echo 'YES, ' . $str . ' is a valid url';
} else {
echo 'NO!, ' . $str . ' is NOT a valid url';
}