Skip to content

Instantly share code, notes, and snippets.

@dlion
Created April 19, 2013 17:49
Show Gist options
  • Save dlion/5421955 to your computer and use it in GitHub Desktop.
Save dlion/5421955 to your computer and use it in GitHub Desktop.
check if is a url
<?php
public function checkURL($url) {
$reg = '%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu';
$url = htmlspecialchars(trim($url));
if(preg_match($reg,$url))
return true;
else
{
$url = "http://".$url;
return (preg_match($reg,$url)) ? true : false;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment