Skip to content
PHP client for the / API
Branch: master
Clone or download
Latest commit feebdfc Feb 21, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
library/HtmlValidator Change from bool to options array when validating URLs Feb 21, 2017
tests Change from bool to options array when validating URLs Feb 21, 2017
.gitignore Added phpunit.xml to gitignore Jun 18, 2014
.travis.yml Test on latest PHP version Feb 21, 2017
LICENSE Update copyright year Aug 7, 2016 Add badges to readme Feb 21, 2017
composer.lock Use Guzzle 6.2 Aug 7, 2016
phpunit.xml.dist Change backend from to Feb 21, 2017
phpunit.xml.travis Change backend from to Feb 21, 2017


PHP client for the API. Can be configured to use a self-hosted version of the API.

Latest Stable VersionPHP VersionLicenseBuild Status

Version >= 2.0.0 requires PHP >= 5.6.
Version <= 1.1.0 supports PHP <= 5.6, but won't be maintained anymore.


$document = file_get_contents('my-page.html');

$validator = new HtmlValidator\Validator();
$result = $validator->validateDocument($document);

$result->hasErrors();   // true / false
$result->hasWarnings(); // true / false

$result->getErrors();   // array(HtmlValidator\Message)

echo $result;           // Prints all messages in human-readable format
echo $result->toHTML(); // Prints all messages HTML-formatted


To include html-validator in your project, add it to your composer.json file:

    "require": {
        "rexxars/html-validator": "^2.1.0"


Document to be validated (validate-me.html):

    <title>Invalid HTML4!</title>
    <p>This document is not a proper, well-formed HTML4 document!</p>
    <p>It contains fatal flaws, like:</p>
        <li><div> tags which are not closed</li>
        <li>span-tags which are never opened are attempted closed </span></li>

Using the validator:

$document = file_get_contents('validate-me.html');

$validator = new HtmlValidator\Validator();
$result = $validator->validateDocument($document);

echo $result;


info: HTML4-specific tokenization errors are enabled.

error: End tag “li” seen, but there were open elements.
From line 10, column 44; to line 10, column 48
not closed</li>

error: Unclosed element “div”.
From line 10, column 13; to line 10, column 17
      <li><div> tags

error: Stray end tag “span”.
From line 11, column 67; to line 11, column 73
ed closed </span></li>

Validating a URL

Since 1.1.0 you can validate URLs as well:

$validator = new HtmlValidator\Validator();
$result = $validator->validateUrl($url);

echo $result;

Note that if you want to check pages that return status codes that are not in the 2xx-range (like a 404-page), you need to pass a checkErrorPages option:

$validator = new HtmlValidator\Validator();
$result = $validator->validateUrl($url, ['checkErrorPages' => true]);

echo $result;

Using a self-hosted version of the API

Check out for instructions on setting up the service. Once set up, you can configure the validator to use a different host:

$validator = new HtmlValidator\Validator('');


MIT licensed. See LICENSE for full terms.

You can’t perform that action at this time.