dev-master
9999999-dev https://github.com/rottingham/UrlValidatorValidate URL form, Validate Header Existance and Reformat URLs
MIT
The Requires
- php >=5.0
url validate format
Validate URL form, Validate Header Existance and Reformat URLs
Utility Class to validate URL string as well as determine if the URL exists., (*1)
For extended usage examples, see test files., (*2)
Composer Ready, (*3)
Available on Packagist: https://packagist.org/packages/rottingham/urlvalidator, (*4)
Simply import the Urlvalidator.class.php
file into your project if you are not using dependency injection., (*5)
require __DIR__ . '/src/UrlValidator.class.php';
To validate a URL string, use the UrlValidator::validate(url)
method;, (*6)
$url = 'http://www.yahoo.com'; $isValid = UrlValidator\UrlValidator::validate($url); var_dump($isValid);
To determine if a URL actaully exists, IE the domain exists and the URL request is not bounced, use the UrlValidator::exists(url)
method;, (*7)
$url = 'http://www.yahoo.com'; $exists = UrlValidator\UrlValidator::exists($url); var_dump($exists);
Note: UrlValidator::exists(url)
calls UrlValidator::validate(url)
and will return FALSE if the URL is invalid before every checking the URL headers., (*8)
You can attempt to reformat a bad URL with the UrlValidator::reformat(url)
method. This method is far from perfect, but since www.yahoo.com
is technically an invalid URL, it can be quite useful., (*9)
$url = 'google.com'; $newUrl = UrlValidator\UrlValidator::reformat($url); var_dump($newUrl); // Outputs array (size=2) 'original' => `google.com` 'url' => 'http://wwww.google.com'
Validate URL form, Validate Header Existance and Reformat URLs
MIT
url validate format