๐ŸŒ
W3C
validator.w3.org
The W3C Markup Validation Service
This validator checks the markup validity of Web documents in HTML, XHTML, SMIL, MathML, etc. If you wish to validate specific content such as RSS/Atom feeds or CSS stylesheets, MobileOK content, or to find broken links, there are other validators and tools available.
W3 Nu Html Checker
This tool is an ongoing experiment in better HTML checking, and its behavior remains subject to change ยท Show sourceoutlineimage reporterrors & warnings onlycheck error pagesUser-Agent Accept-Language
W3C Feed Validation Service, for Atom and RSS
Check the syntax of Atom or RSS feeds ยท Validate a feed online:
Broken Link Checker
This Link Checker looks for issues in links, anchors and referenced objects in a Web page, CSS style sheet, or recursively on a whole Web site. For best results, it is recommended to first ensure that the documents checked use Valid (X)HTML Markup and CSS.
validator service by the World Wide Web Consortium
The Markup Validation Service is a validator by the World Wide Web Consortium (W3C) that allows Internet users to check pre-HTML5 HTML and XHTML documents for well-formed markup against a document type โ€ฆ Wikipedia
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_form_validation.asp
PHP Form Validation
These pages will show how to process PHP forms with security in mind. Proper validation of form data is important to protect your form from hackers and spammers! The HTML form we will be working at in these chapters, contains various input fields: required and optional text fields, radio buttons, ...
๐ŸŒ
Nusphere
nusphere.com โ€บ products โ€บ php_code_validator.htm
PHP, HTML, and CSS code Validator
PhpED - PHP IDE integrated development environment for developing web sites using PHP, HTML, Perl, JScript and CSS that combines a comfortable editor, debugger, profiler with the MySQl, PostrgeSQL database support based on easy wizards and tutorials.Easy to use for debugging PHP scripts, publishing ...
๐ŸŒ
Htmlvalidator
htmlvalidator.com โ€บ php-script-checker.php
PHP Syntax Checking with CSS HTML Validator
CSS HTML Validator - The all-in-one HTML & CSS web development tool for Windows, & console tool for Mac and Linux ... CSS HTML Validator (Home+) can integrate with PHP's syntax checker for easy PHP script/code syntax checking.
๐ŸŒ
GitHub
github.com โ€บ rexxars โ€บ html-validator
GitHub - rexxars/html-validator: PHP client for the Validator.nu / checker.html5.org API
{ "require": { "rexxars/html-validator": "^2.2.0" } } ... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Invalid HTML4!</title> </head> <body> <p>This document is not a proper, well-formed HTML4 document!</p> <p>It contains fatal flaws, like:</p> <ul> <li><div> tags which are not closed</li> <li>span-tags which are never opened are attempted closed </span></li> </ul> </body> </html> ... <?php $document = file_get_contents('validate-me.html'); $validator = new HtmlValidator\Validator(); $validator->setParser(HtmlValidator\Validator::PARSER_HTML4); $result = $validator->validateDocument($document); echo $result;
Starred by 31 users
Forked by 7 users
Languages ย  PHP 100.0% | PHP 100.0%
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ micheh โ€บ w3c-validator
GitHub - micheh/w3c-validator: PHP library to validate HTML using the W3C HTML Validator API, including a checkstyle formatter for CI ยท GitHub
PHP library to validate HTML using the W3C HTML Validator API, including a checkstyle formatter for CI - micheh/w3c-validator
Starred by 9 users
Forked by 10 users
Languages ย  PHP
Top answer
1 of 2
9

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

  • DOMDocument::validate โ€” Validates the document based on its DTD

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()

2 of 2
1

I asked a similar question and you might check out some of the answers there.

In summary, I would recommend either running the HTML through tidy on the host or writing a short script to validate through W3C remotely. Personally, I don't like the tidy option because it reformats your code and I hate how it puts <p> tags on every line.

Here's a link to tidy and here's a link to the various W3C validation tools.

One thing to keep in mind is that HTML validation doesn't work with server-side code; it only works after your PHP is evaluated. This means that you'd need to run your code through the host's PHP interpreter and then 'pipe' it to either the tidy utility or the remote validation service. That command would look something like:

$ php myscript.php | tidy #options go here

Personally, I eventually chose to forgo the headache and simply render the page, copy the source and validate via direct input on the W3C validation utility. There are only so many times you need to validate a page anyway and automating it seemed more trouble than it's worth.

Good luck.

๐ŸŒ
PHP
pear.php.net โ€บ manual โ€บ en โ€บ package.html.html-quickform.intro-validation.php
validation and filters โ€“ How to process submitted data
You can define your own validation rules and apply them to the elements or groups you want. In this section, we will explore the different possibilities QuickForm offers to make validation easier. QuickForm can verify if required elements are filled when the form is submitted. This works with every type of elements or groups, integer 0 is not considered as an empty value. <?php require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm('myform', 'post'); $form->addElement('text', 'email', 'Your email:'); $form->addElement('submit', 'submit', 'Submit'); // Validation rules $form->addRule('email', 'E-Mail is required', 'required'); // Validation if ($form->validate()) { $form->freeze(); } $form->display(); ?>
๐ŸŒ
PHP
pear.php.net โ€บ package โ€บ Services_W3C_HTMLValidator
Services_W3C_HTMLValidator
Search for in the Packages This site (using Yahoo!) Developers Developer mailing list General mailing list SVN commits mailing list ยท Not sure? Get more info
๐ŸŒ
BairesDev
bairesdev.com โ€บ tools โ€บ phpcodechecker
PHP Code Checker - Syntax Check for Common PHP Mistakes
An advanced, custom PHP code checker that searches your code for common, hard to find typos and mistakes; includes a syntax check.
๐ŸŒ
ExtendsClass
extendsclass.com โ€บ php-tester.html
PHP Code Checker - Online syntax check
PHP error checker tool allows to find syntax errors (lint). You can test your PHP code online directly in your browser. In case of a detected syntax error, the tool highlights the erroneous line and swiftly navigates to it, eliminating the need for manual line-by-line searches and saving valuable ...
๐ŸŒ
SitePoint
sitepoint.com โ€บ blog โ€บ patterns & practices โ€บ form validation with php
Form Validation with PHP โ€” SitePoint
November 13, 2024 - In this article, weโ€™ll build and validate a small web form using HTML and PHP. The form is created using HTML, and validation and processing of the formโ€™s contents is done with PHP.
๐ŸŒ
PHP
pear.php.net โ€บ manual โ€บ en โ€บ package.html.html-quickform2.rules.php
Rules and validation โ€“ Checking that you get the values ...
HTML_QuickForm2 allows validation of elements based on values and validation status of other elements. This is done by building a "chain" of validation rules using HTML_QuickForm2_Rule::and_() and HTML_QuickForm2_Rule::or_() methods. Execution of the chain starts with a rule that was added ...
๐ŸŒ
validator
unicframework.github.io โ€บ validator
Validator | validator
January 9, 2026 - Validator is a server side data validation library for PHP. Validate html form-data, objects, arrays and json etc.