PHP code example of avplab / php-html-builder

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

    

avplab / php-html-builder example snippets



$builder = new \AvpLab\PhpHtmlBuilder();
$builder
    ->tag('!DOCTYPE')->setHtml()->endOpened()
    ->html()->setLang('en')
        ->head()
            ->meta()->setHttpEquiv('X-UA-Compatible')->setContent('IE=edge,chrome=1')->endOpened()
            ->title('PhpHtmlBuilder: Example')->end()
        ->end()
        ->body()
            ->div()->setClass('container')
                ->div()->setClass('row')
                    ->div()->setClass('col-md-12')
                        ->h1('PhpHtmlBuilder Demo')->end()
                        ->p('Designed to make the code easier')->end()
                    ->end()
                ->end()
            ->end()
        ->end()
    ->end();

echo $builder;

$builder = new \AvpLab\PhpHtmlBuilder();
echo $builder->html()->customTag()->end()->end();

//Result
<html><custom-tag></custom-tag></html>

$builder = new \AvpLab\PhpHtmlBuilder();
echo $builder->tag('!DOCTYPE')->endOpened();

//Result
<!DOCTYPE>

$builder = new \AvpLab\PhpHtmlBuilder();
echo $builder
    ->div('<h1>title</h1>', ['class' => 'container', 'Foo' => 'Bar', 'baz'])
        ->p(['class' => 'article'])->end()
    ->end();

//Result
<div class="container" Foo="Bar" baz><h1>title</h1><p class="article"></p></div>

$builder = new \AvpLab\PhpHtmlBuilder();
$builder
    ->tag('!DOCTYPE')->setHtml()->endOpened()
    ->html()->setLang('en')->end();

//Result
<!DOCTYPE html><html lang="en"></html>

$builder = new \AvpLab\PhpHtmlBuilder();
$builder
    ->div()
        ->addText('foo')
        ->addHtml('<b>bar</b>')
    ->end();

//Result
<div>foo<b>bar</b></div>

$builder = new \AvpLab\PhpHtmlBuilder();
// Do some html

$htmlString = $builder->build();
echo $htmlString;

// Supports string recognision
echo $builder;

$builder = new \AvpLab\PhpHtmlBuilder();
echo $builder->addComment('foo');

//Result
<!--foo-->