Skip to content

Instantly share code, notes, and snippets.

@guimadaleno
Created September 1, 2022 15:28
Show Gist options
  • Save guimadaleno/6e08de6116f4d46926d4c95361af2e97 to your computer and use it in GitHub Desktop.
Save guimadaleno/6e08de6116f4d46926d4c95361af2e97 to your computer and use it in GitHub Desktop.
Is valid URL function
<?php
/**
* Test if URL is valid
* @author SpikeZ
* @param string $str
* @return bool
*/
function is_valid_url ($uri)
{
if (preg_match( '/^(http|https):\\/\\/[a-z0-9_]+([\\-\\.]{1}[a-z_0-9]+)*\\.[_a-z]{2,5}'.'((:[0-9]{1,5})?\\/.*)?$/i' ,$uri))
return $uri;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment