Skip to content

Instantly share code, notes, and snippets.

@heinrichreimer
Created October 7, 2013 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heinrichreimer/45f0671b6e4c27281b6a to your computer and use it in GitHub Desktop.
Save heinrichreimer/45f0671b6e4c27281b6a to your computer and use it in GitHub Desktop.
function validate_url($url){
$result = preg_match("/^(https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})(\/([\da-z\.-]+))*\/?(([\w\.-]+)\.([\da-z]{2,6}))?((\#[\w\.-]+)|(\?([\da-z]+(=[\da-z]+)?)(&([\da-z]+(=[\da-z]+)?))*))?/i", $url);
return $result;
}
/*Usage*/
if(validate_url("http://heinrich-reimer.de")){
/*Do something*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment