https://github.com/phpfui/phpfuiwebsite
PHPFUI documentation
https://github.com/phpfui/phpfuiwebsite
Last synced: 2 months ago
JSON representation
PHPFUI documentation
- Host: GitHub
- URL: https://github.com/phpfui/phpfuiwebsite
- Owner: phpfui
- Created: 2019-12-31T22:37:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-02-01T06:22:20.000Z (3 months ago)
- Last Synced: 2025-02-06T20:42:45.334Z (3 months ago)
- Language: PHP
- Size: 22.4 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
html-validator
==============PHP client for the [validator.nu](https://validator.nu/) API. Can be configured to use a self-hosted version of the API.
[](https://packagist.org/packages/rexxars/html-validator)[](https://php.net)[](https://packagist.org/packages/rexxars/html-validator)[](https://travis-ci.org/rexxars/html-validator)
Version >= 2.0.0 requires PHP >= 5.6.
Version <= 1.1.0 supports PHP <= 5.6, but won't be maintained anymore.# Usage
```php
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
```# Installing
To include `html-validator` in your project, add it to your `composer.json` file:
```json
{
"require": {
"rexxars/html-validator": "^2.2.0"
}
}
```# Example
Document to be validated (`validate-me.html`):
``` htmlInvalid HTML4!
This document is not a proper, well-formed HTML4 document!
It contains fatal flaws, like:
- tags which are not closed
- span-tags which are never opened are attempted closed
```
Using the validator:
```php
setParser(HtmlValidator\Validator::PARSER_HTML4);
$result = $validator->validateDocument($document);echo $result;
```Output:
```
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 closederror: Unclosed element “div”.
From line 10, column 13; to line 10, column 17
tagserror: Stray end tag “span”.
From line 11, column 67; to line 11, column 73
ed closed```
# Validating a URL
Since 1.1.0 you can validate URLs as well:
```php
setParser(HtmlValidator\Validator::PARSER_HTML5);
$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:
```php
$validator = new HtmlValidator\Validator();
$validator->setParser(HtmlValidator\Validator::PARSER_HTML5);
$result = $validator->validateUrl($url, ['checkErrorPages' => true]);echo $result;
```# Using a self-hosted version of the API
Check out [validator.nu](http://about.validator.nu/#src) for instructions on setting up the service.
Once set up, you can configure the validator to use a different host:```php