PHP code example of il4mb / blocknode

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

    

il4mb / blocknode example snippets




use Il4mb\BlockNode\Node;

hildren" => [
        "<div class=\"test 1\"></div>"
    ],
    "class" => "test"
]);

$node->query(".test")->prepend("<p>Hallo</p>", 1);
echo $node;

// Output: <div class="test"><p>Hallo</p><div class="test 1"></div></div>

$node = new Node("div", [
    "id" => "container",
    "children" => [
        "<p>Hello, World!</p>"
    ],
    "class" => "main"
]);

echo $node;
// Output: <div id="container" class="main"><p>Hello, World!</p></div>

$node = new Node("div", [
    "children" => [
        "<div class=\"child\"></div>",
        "<p class=\"child\">Text</p>"
    ]
]);

$childNodes = $node->query(".child");
echo $childNodes;
// Output: <div class="child"></div><p class="child">Text</p>

$node->append("<span>New Content</span>");
echo $node;
// Appends content as a child to the node.

$node->prepend("<span>First Content</span>");
echo $node;
// Prepends content as the first child of the node.

$node->append("<div class=\"dynamic\">Dynamic Content</div>");

$node = new Node("ul", [
    "children" => [
        ["tagName" => "li", "attribute" => ["class" => "item"], "children" => ["Item 1"]],
        "<li>Item 2</li>",
    ]
]);

echo $node;
// Output: <ul><li class="item">Item 1</li><li>Item 2</li></ul>