简体   繁体   English

PHP文件中的HTML验证

[英]HTML Validation in PHP File

I am working on some Apache Ant Project in which i am using .jar to validate html. 我正在使用Apache .jar来验证HTML的Apache Ant项目。 The ant script takes the *.html files and validate it and display if errors are found. ant脚本获取* .html文件并对其进行验证,并在发现错误时显示。

The .jar is not working for validation of html written in .php file. .jar无法用于验证以.php文件编写的html。 because it does not accept .php file. 因为它不接受.php文件。

Do some one knows any .jar or .js or .php file/method through which i can validate html within .php file. 是否有人知道任何.jar或.js或.php文件/方法,通过它们我可以验证.php文件中的html。

NOTE: i don't want to use w3c-Validate tool as it is online and will only work if internet is on. 注意:我不想使用w3c-Validate工具,因为它是在线的,并且只有在Internet开启的情况下才可以使用。

You won't be able to validate the .php files directly, because PHP is not HTML. 您将无法直接验证.php文件,因为PHP不是HTML。 It can include embedded HTML or generate HTML programatically, but that's not the same thing. 它可以包含嵌入式HTML或以编程方式生成HTML,但这不是一回事。

You will need to employ a number of techniques to validate the PHP. 您将需要采用多种技术来验证PHP。 The simplest tool is simply to run it, or run php -l to get a report on the syntax of the file in question. 最简单的工具就是运行它,或者运行php -l以获取有关该文件语法的报告。 To actually test that the script is operating as intended will require testing tools such as PHPUnit and Selenium. 要实际测试脚本是否按预期运行,将需要测试工具,例如PHPUnit和Selenium。

To test that the output is valid HTML, you could save the pages generated by the script and run them through the validator, or you could pipe the output from PHP into the input for the validator. 要测试输出是否为有效的HTML,可以保存脚本生成的页面并通过验证器运行它们,也可以将PHP的输出通过管道传递给验证器的输入。 For example, 例如,

php -f /path/to/my/script.php | java my_html_validator.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM