zsxsoft / php-w3c-validator
vnu.jar (Nu Html Checker) 的 PHP 绑定
Requires
- php: >=5.6.4
Requires (Dev)
- evert/phpdoc-md: ~0.2.0
- phpdocumentor/phpdocumentor: 2.*
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2022-06-23 06:18:00 UTC
README
用于The Nu Html Checker (v.Nu)的包装器
当前版本:17.11.1
注意
您需要安装 Java 以使用
php-w3c-validator
如果您没有 Java,请访问 https://java.com 下载 Java
安装
composer require zsxsoft/php-w3c-validator
测试
phpunit
用法
推荐
<?php use Zsxsoft\W3CValidator\W3CValidator; $validator = new W3CValidator(); print_r($validator->fileName('http://localhost')->run());
<?php use Zsxsoft\W3CValidator\W3CValidator; $validator = new W3CValidator(); print_r($validator->data('<html></html>')->run());
结果
Array( [normal] => NULL [error] => stdClass Object ( [messages] => Array ( [0] => stdClass Object ( [type] => error [lastLine] => 1 [lastColumn] => 6 [firstColumn] => 1 [message] => Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”. [extract] => <html></html [hiliteStart] => 0 [hiliteLength] => 6 ) [1] => stdClass Object ( [type] => error [lastLine] => 1 [lastColumn] => 13 [firstColumn] => 7 [message] => Element “head” is missing a required instance of child element “title”. [extract] => <html></html> [hiliteStart] => 6 [hiliteLength] => 7 ) ) ) )
API
__construct
mixed Zsxsoft\W3CValidator\W3CValidator::__construct(string $jarPath)
W3CValidator 构造函数。
参数
- $jarPath string
data
$this|string Zsxsoft\W3CValidator\W3CValidator::data(string $data)
获取或直接设置 HTML 数据
fileName
$this|string Zsxsoft\W3CValidator\W3CValidator::fileName(string $data)
获取或设置文件,"-" 表示由 data 设置的文本。
- 默认: -
run
mixed|array Zsxsoft\W3CValidator\W3CValidator::run()
运行验证器
exec
array Zsxsoft\W3CValidator\W3CValidator::exec($argument, $callback = NULL)
使用自定义参数运行验证器
javaArgument
$this|string Zsxsoft\W3CValidator\W3CValidator::javaArgument(string $data)
获取或设置 Java 参数
参数
- $argument mixed
- $callback callable - 管道回调
命令行参数
有关帮助,请参阅 https://github.com/validator/validator
asciiquotes
$this|string Zsxsoft\W3CValidator\W3CValidator::asciiquotes()
指定是否在消息中用 ASCII 引号替换 Unicode 智能引号。
errors_only
$this|string Zsxsoft\W3CValidator\W3CValidator::errors_only()
指定仅报告错误级别的消息和非文档错误消息(因此不报告警告和信息消息)。
Werror
$this|string Zsxsoft\W3CValidator\W3CValidator::Werror()
如果遇到任何警告,检查器将退出非零(即使没有错误)。
exit_zero_always
$this|string Zsxsoft\W3CValidator\W3CValidator::exit_zero_always()
即使任何文档报告错误,检查器也将退出零。
filterfile
$this|string Zsxsoft\W3CValidator\W3CValidator::filterfile()
指定文件名。文件中的每一行包含一个正则表达式或者以“#”开头表示该行为注释。文件中与正则表达式匹配的任何错误消息或警告消息将被过滤掉(丢弃/抑制)。
filterpattern
$this|string Zsxsoft\W3CValidator\W3CValidator::filterpattern()
指定正则表达式模式。与该模式匹配的任何错误消息或警告消息将被过滤掉(丢弃/抑制)。
format
$this|string Zsxsoft\W3CValidator\W3CValidator::format()
指定结果报告的输出格式。
- 默认值:json
skip_non_html
$this|string Zsxsoft\W3CValidator\W3CValidator::skip_non_html()
跳过没有*.html、*.htm、*.xhtml或*.xht扩展名的文档。
html
$this|string Zsxsoft\W3CValidator\W3CValidator::html()
强制任何*.xhtml或*.xht文档使用HTML解析器进行解析。
no_langdetect
$this|string Zsxsoft\W3CValidator\W3CValidator::no_langdetect()
禁用语言检测,因此文档不会被检查缺少或标记错误的html[lang]属性。
no_stream
$this|string Zsxsoft\W3CValidator\W3CValidator::no_stream()
强制所有文档以缓冲模式而不是流模式进行解析(导致某些解析错误被视为非致命文档错误而不是致命文档错误)。
verbose
$this|string Zsxsoft\W3CValidator\W3CValidator::verbose()
指定“详细”输出。(目前这仅仅意味着正在检查的文件名将被写入stdout。)
version
$this|string Zsxsoft\W3CValidator\W3CValidator::version()
显示vnu.jar版本号。
许可证
MIT许可证