PHP code example of seasonfive / html-validator

1. Go to this page and download the library: Download seasonfive/html-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

seasonfive / html-validator example snippets


$validator = new Validator([
    'tags' => [
        'deny' => ['script', 'svg', 'img'],
        'overrides' => ['a' => ['img']]
    ],
    'attrs' => [
        'allow' => ['href', 'div' => ['data-role']]
    ]
]);

if ($validator->validate('<a href="http://example.com">link</a>')) {
    print "Valid!!\n";
}

if (!$validator->validate('<a href="http://example.com">link</a>', false, $errors)) {
    var_dump($errors);
}

[
    'tags' => [
        'allow' => ['script', 'div' => ['p', 'a']]
     ],
    'attrs' => [
        'deny' => ['onmouseover', 'onclick'],
        'overrides' => ['a' => ['onclick'], 'html' => ['body' => ['div' => 'onmouseover']]]    
    ]
]

[
    'tags' => [
        'allow' => ['script', 'div' => new TypeMatcher()]
    ]
]

public function match(array $path, $context, string &$reason): bool