PHP code example of zisunal / php-html

1. Go to this page and download the library: Download zisunal/php-html 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/ */

    

zisunal / php-html example snippets




use Zisunal\PhpHtml\Html;

use Zisunal\PhpHtml\Htm;

    Htm::div(['class' => 'container'],
        Htm::h1('Hello World')
        ->hr(),
        Htm::p('This is a static paragraph.')
    );
    

    $html = new Html();
    

    // This code will generate a whole Html document starting from <!DOCTYPE html> to the ending </html>
    $html->title('My Page');
    

    // This code will generate a div element with a class of "container" without the full Html document
    $html->divOpen(['class' => 'container'])
            ->h1Open()
                ->innerText('Hello World')
            ->h1Close()
            ->hr
            ->pOpen()
                ->innerText('This is a static paragraph.')
            ->pClose();
        ->divClose()
    ->render();
    // Notice that we can open and close almost all the container tags anywhere and add any content inside them.
    

    $html->div(['class' => 'container'],
        $html->h1Open()
            ->innerText('Hello World')
        ->h1Close()
        ->hr
        ->pOpen()
            ->innerText('This is a static paragraph.')
        ->pClose();
    )->render();
    // Notice that, we are passing the attributes of <div> in the 1st argument and any number of Html/Htm in the 2nd, 3rd, ..... arguments
    

    $html->div(['class' => 'container'],
        $html->h1('Hello World')->hr->p('This is a static paragraph.')
    )->render();
    // You can use shorter syntax for the most useful container tags and to all the self-closing tags
    

    Htm::div(['class' => 'container'],
        Htm::h1('Hello World'),
        Htm::hr(),
        Htm::p('This is a static paragraph.')
    )->render();
    

    $html->title('My Title')
        ->p('My Paragraph')
        ->minify()
        ->render();
    // If you view the page source, you will see the minified output.
    

    $html->divOpen(['class' => 'container'])
        ->h1Open()
            ->innerText('Hello World')
        ->h1Close()
        ->hr()
        ->pOpen()
            ->innerText('This is a static paragraph.')
        ->pClose()
    ->divClose();
    

    $html->input([
        'class' => 'img-fluid',
        'name' => 'fullName',
        'id' => 'fullName',
        'placeholder' => 'Enter your full name',
        '

    $html->img('image.jpg', 'Alt Text', ['class' => 'img-fluid']);
    

    $html->h1('Hello World', ['class' => 'title']);
    // Same as:
    $html->h1Open(['class' => 'title'])
        ->innerText('Hello World')
    ->h1Close();