我可以从 php 脚本以编程方式验证 xhtml 吗? [英] can i validate xhtml programmatically from a php script?

查看:24
本文介绍了我可以从 php 脚本以编程方式验证 xhtml 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个 PHP 函数来检查 URL 是否返回有效的 HTML,并返回 true 或 false.

I would like to have a PHP function to check if a URL returns valid HTML or NOT, and returns true or false.

类似于:

if (validate_page("/somefile.html")) { echo "此页面已验证!!";}

if (validate_page("/somefile.html")) { echo "This page validated!!"; }

我找到了 TWINE,但它不只是给我真假.另外我在我的系统上运行它时出错.http://twineproject.sourceforge.net/

I found TWINE but it doesn't just give me true or false. Also I got an error running it on my system. http://twineproject.sourceforge.net/

我发现这个看起来很有前途的离线工具.http://htmlhelp.com/tools/validator/offline/

I found this offline tool that looked promising. http://htmlhelp.com/tools/validator/offline/

我还发现了这个讨论宝石的帖子,但听起来有问题.如何使用 nokogiri 验证 XHTML?

Also I found this thread that talks about a gem, but it sounds problematic. How do I validate XHTML with nokogiri?

推荐答案

您可以使用 W3C 的验证器API.PEAR 提供了一个 PHP 库(点击此处),它使用了上述 API.

You can use W3C's validator API. There's a PHP library available through PEAR (click here) which uses said API.

您也可以在本地服务器上安装验证器(此处的说明),如果您使用的是共享主机,则可能没有足够的权限来执行此操作.

You can also install the validator on your local server (instructions here), though you might not have sufficient permissions to do so if you are using shared hosting.

这篇关于我可以从 php 脚本以编程方式验证 xhtml 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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