HTML5 Parsing and Writing in PHP is finally here.
Parsing
Parse html5 files, documents, and fragments to standard PHP DOM objects. </div>
Writing (Serializing)
Turn standard DOM documents, fragments, and node lists into html5.
Configure It
Set default and call time options in the basic parser and serializer.
Build Your Own
Use the parts to build your own parser or serializer that does what you need.
Installation
The best installation method is via composer. To install add masterminds/html5-php
to your composer.json
file.
{
"require" : {
"masterminds/html5": "2.*"
},
}
From there, use the composer install
or composer update
commands to install.
Basic Usage
// An example HTML document:
$html = "<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body id='foo'>
<h1>Hello World</h1>
<p>This is a test of the HTML5 parser.</p>
</body>
</html>";
use Masterminds\HTML5;
$html5 = new HTML5();
// Parse the document. $dom is a DOMDocument.
$dom = $html5->loadHTML($html);
print $html5->saveHTML($dom);
It's that easy. See the documentation for all the wonderful ways to parse and write html5.