2017 © Pedro Peláez
 

library urlvalidator

Validate URL form, Validate Header Existance and Reformat URLs

image

rottingham/urlvalidator

Validate URL form, Validate Header Existance and Reformat URLs

  • Friday, November 8, 2013
  • by rottingham
  • Repository
  • 1 Watchers
  • 0 Stars
  • 38 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

UrlValidator

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)

Sample Usage

Simply import the Urlvalidator.class.php file into your project if you are not using dependency injection., (*5)

require __DIR__ . '/src/UrlValidator.class.php';
Valiate URL

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);

Check if URL Exists

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)

Reformat URL

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'

The Versions

08/11 2013

dev-master

9999999-dev https://github.com/rottingham/UrlValidator

Validate URL form, Validate Header Existance and Reformat URLs

  Sources   Download

MIT

The Requires

  • php >=5.0

 

url validate format