PHP code example of patrickschur / html5gen

1. Go to this page and download the library: Download patrickschur/html5gen library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

patrickschur / html5gen example snippets



 
use Html5Gen\Html5Gen as H; // shorthand
 
echo
H::html([], function() {
    H::head();
    H::body();
});

echo
H::html(['lang' => 'en', 'dir' => 'ltr'], function() {
    H::head();
    H::body([], function () {
        H::p(['class' => 'foo bar']);
    });
});

echo
H::html([], function() {
    H::head([], function () {
        H::meta(['charset' => 'UTF-8']);
    });
    H::body([], function ()
    {
        foreach (range(0, 10) as $number) {
            H::p([], function () use ($number) {
                yield $number;
            });
        }
    });
});

echo
H::html([], function() {
    H::head([]);
    H::body([], function () {
        // A really bad attribute value
        H::pre(['id' => '"\'"'], function () {
            yield '<script>alert(1);</script>'; // maybe some user code?
        });
        
        // Be careful with that and do not use user code in it
        H::script([], function () {
            yield 'var x = Math.floor(Math.random() * 100);';
            yield 'alert(0 < x < 100);';
        });
    });
});