Created
July 4, 2012 15:48
-
-
Save Maks3w/3047965 to your computer and use it in GitHub Desktop.
Actual way of treat URIs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function verifyUri($value) { | |
try { | |
$uri = Zend\Uri\UriFactory::factory($value) | |
} catch (Zend\Uri\Exception\InvalidUriPartException $e) { | |
return false; | |
} | |
return $uri->isValid(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function verifyUri($value) { | |
$uri = Zend\Uri\UriFactory::factory($value) | |
return $uri->isValid(); | |
} | |
// Or | |
function verifyUri($value) { | |
$uri = Zend\Uri\UriFactory::factory($value) | |
if (!$uri->isValid()) { | |
$errno = $uri->getErrorCode(); | |
$message = $uri->getErrorMessage(); | |
throw new Exception($message, $errno); | |
} | |
return true; | |
} | |
/* | |
Error Messages: | |
- Invalid part syntax | |
Invalid [Schema|Hostname|Port|Parh|...] | |
- Invalid URI syntax | |
Uri not valid by schema restriction <restriction detail> | |
Uri global syntax not valid. See RFC 3986 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment