PHP中的X / Html Validator [英] X/Html Validator in PHP

查看:123
本文介绍了PHP中的X / Html Validator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一件事:我知道有W3C验证器的接口: http://pear.php。 net / package / Services_W3C_HTMLValidator /
但我不知道我是否可以将它安装在廉价的托管服务器上。我不这么认为。



我需要我的内容管理系统中的seo工具的验证器,因此它必须非常便于携带。



我喜欢使用W3C,但前提是它是可移植的。我也可以使用Curl,但它不会是优雅的解决方案。



到目前为止,我发现的最好的一个是: http://phosphorusandlime.blogspot.com/2007/09/php-html-validator-class.html a>

是否有任何验证工具与W3C相媲美,但可移植(只有PHP不依赖于定制包)?

如果您想验证(X)HTML文档,您可以使用PHP的本地 DOM 扩展名:





手册中的例子:

  $ dom = new DOMDocument; 
$ dom-> load('book.xml'); //见load,loadXml,loadHtml和loadHtmlFile的文档$ b $ if if($ dom-> validate()){
echoThis document is valid!\\\
;

$ / code $ / pre

如果你想要单个错误,请使用 libxml_get_errors()

First thing: I know that there is interface to W3C validator: http://pear.php.net/package/Services_W3C_HTMLValidator/ But I don't know if I can install it on cheap hosting server. I don't think so.

I need validator for my seo tools within my Content Managment System so it must be pretty much portable.

I would love to use W3C but only if it would be portable. I can also use Curl for this but it won't be elegant solution.

The best one I found so far is: http://phosphorusandlime.blogspot.com/2007/09/php-html-validator-class.html

Is there any validator comparable to W3C but portable (only PHP that does not depend on custom packages)?

解决方案

If you want to validate (X)HTML documents, you can use PHP's native DOM extension:

Example from Manual:

$dom = new DOMDocument;
$dom->load('book.xml'); // see docs for load, loadXml, loadHtml and loadHtmlFile
if ($dom->validate()) {
    echo "This document is valid!\n";
}

If you want the individual errors, fetch them with libxml_get_errors()

这篇关于PHP中的X / Html Validator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆