简体   繁体   中英

HTML Validation in PHP File

I am working on some Apache Ant Project in which i am using .jar to validate html. The ant script takes the *.html files and validate it and display if errors are found.

The .jar is not working for validation of html written in .php file. because it does not accept .php file.

Do some one knows any .jar or .js or .php file/method through which i can validate html within .php file.

NOTE: i don't want to use w3c-Validate tool as it is online and will only work if internet is on.

You won't be able to validate the .php files directly, because PHP is not HTML. It can include embedded HTML or generate HTML programatically, but that's not the same thing.

You will need to employ a number of techniques to validate the 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. To actually test that the script is operating as intended will require testing tools such as PHPUnit and 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. For example,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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