Skip to content

Instantly share code, notes, and snippets.

@Maks3w
Created July 4, 2012 15:48
Show Gist options
  • Save Maks3w/3047965 to your computer and use it in GitHub Desktop.
Save Maks3w/3047965 to your computer and use it in GitHub Desktop.
Actual way of treat URIs
<?php
function verifyUri($value) {
try {
$uri = Zend\Uri\UriFactory::factory($value)
} catch (Zend\Uri\Exception\InvalidUriPartException $e) {
return false;
}
return $uri->isValid();
}
<?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