/dom

Handle HTML5 and CSS3 easily

Primary LanguagePHPApache License 2.0Apache-2.0

PHP DOM

Handle HTML5 and CSS3 easily

An example to see how the code works :

The Styper code

<html>
[lang="fr"]
{color:red;}
(
    <head>
    (
        <meta>[charset="UTF-8"]
        <title>(Styper source)
    )
    <body>
    (
        <p>[id="main-content"]{color:blue}(Welcome to Styper !)
    )
)

The equivalent HTML5 code

<!DOCTYPE html>
<html lang="fr">
    <head>
        <meta charset="UTF-8"/>
        <title>Styper source</title>
        <style>
        html
        {
            color: red;
        }
        p#main-content
        {
            color: blue;
        }
        </style>
    </head>
    <body>
        <p>Welcome to Styper !</p>
    </body>
</html>

The equivalent PHP5 code

<?php use Styper\Document;
require 'vendor/autoload.php';
$document = new Document('html', 5);
$document->setAttribute('lang', 'fr');
$document->setProperty('color', 'red');
$document->head->meta->charset = 'UTF-8';
$document->title = 'Welcome to Styper !';
$p = $document->createElement('p');
$p->setAttribute('id', 'main-content');
$p->setProperty('color', 'red');
$p->setContent('Welcome to Styper !');
$document->prepend($p, $body);
$document->save();