PHP code example of becklyn / html-builder

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

    

becklyn / html-builder example snippets


use Becklyn\HtmlBuilder\Builder\HtmlBuilder;
use Becklyn\HtmlBuilder\Node\HtmlElement;

$builder = new HtmlBuilder();

$link = new HtmlElement("a", [
    "href" => "https://becklyn.com", 
], [
    "Becklyn Studios"
]);

assert('<a href="https://becklyn.com">Becklyn Studios</a>' === $builder->buildElement($link));

use Becklyn\HtmlBuilder\Builder\HtmlBuilder;
use Becklyn\HtmlBuilder\Node\HtmlAttributes;

$builder = new HtmlBuilder();

$attributes = $builder->buildAttributes(new HtmlAttributes([
    "href" => "https://becklyn.com",
    "target" => "_blank",
]));

echo "<a {$attributes}>Becklyn</a>"; 

$full = $builder->build([
    "first" => "a",
    "removed1" => false,
    "removed2" => null,
    "checked" => true,
    "last" => "b",
]);


assert($full === 'first="a" checked last="b"'); // true

$link = new HtmlElement("div");
$link->addContent(new SafeMarkup("This will <b>not</b> be escaped!"));

assert('<div>This will <b>not</b> be escaped!</div>' === $builder->buildElement($link));