PHP code example of airmanbzh / php-html-generator

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

    

airmanbzh / php-html-generator example snippets


return HtmlTag::createElement();
// returns an empty HtmlTag Container

return HtmlTag::createElement('a');
// returns an HtmlTag containing a 'a' tag

echo(HtmlTag::createElement('a'));

$tag = HtmlTag::createElement('a')
echo( $tag );

echo HtmlTag::createElement('div');

echo(HtmlTag::createElement('p')->text('some content'));

echo(HtmlTag::createElement('div')->addElement('a')->text('a text'));

$container = HtmlTag::createElement('div');
$container->addElement('p')->text('a text');
$container->addElement('a')->text('a link');

$tag = HtmlTag::createElement('a')
    ->set('href','./sample.php')
    ->set('id','myID')
    ->text('my link');
echo( $tag );

$tag = HtmlTag::createElement('div')
    ->id('myID');
echo( $tag );

$tag = HtmlTag::createElement('div')
    ->addClass('oneClass')
    ->text('my content')
echo( $tag );

$tag = HtmlTag::createElement('div')
    ->addClass('aClass')
    ->addClass('anothereClass')
    ->text('my content')
echo( $tag );

$tag = HtmlTag::createElement('div')
    ->addClass('firstClass')
    ->addClass('secondClass')
    ->text('my content')
    ->removeClass('firstClass');
echo( $tag );

$tag = HtmlTag::createElement('p')
    ->text('a text')
    ->addElement('a')
    ->text('a link');

$tag = HtmlTag::createElement('p')
    ->addElement('a')
    ->text('a link')
    ->getParent()
    ->text('a text');

$tag = HtmlTag::createElement('p');
$tag->addElement('a')->text('a link');
$tag->text('a text');
html
<a href='./sample.php' id='myID'>my link</a>