PHP Classes

File: example_3_parent_and_child_nodes

Recommend this page to a friend!
  Packages of Tony Frezza   HTML Generate   example_3_parent_and_child_nodes   Download  
File: example_3_parent_and_child_nodes
Role: Example script
Content type: text/plain
Description: Example 3 Parent And Child Nodes
Class: HTML Generate
Generate HTML from arrays
Author: By
Last change: edit class name to UML template
Date: 9 years ago
Size: 1,880 bytes
 

Contents

Class file image Download
<?php

/**
 * @author Tony Frezza
 * @copyright 2017
 */

    include('html.php');
    
    
    $html = new Html;
    
    
    /**
        En: 
            Note that each node relative to a tag is informed by an array.
            Each child node is an array, since it is a tag.
            So, for the children of a parent node, we will have an array of arrays
        
        Pt-BR:
            Observe que cada nó relativo a uma tag é informado por um array.
            Cada nó filho é uma array, uma vez que é uma tag.
            Assim, para os nós filhos de um nó pai, teremos um array de arrays 
     */
     
     
    $html->add(
        array(
            'tag'       =>  'ul',
            'children'  =>  array(
                array(
                    'tag'       =>  'li',
                    'text'      =>  'foo'
                ),
                array(
                    'tag'       =>  'li',
                    'text'      =>  'bar'
                )
            )
        )
    );
    
    echo $html->getHtml();
    
    $html->resetHtml();
    
    $html->add(
        array(
            'tag'       =>  'div',
            'style'     =>  'width: 100%; border: solid; text-align: center;',
            'children'  =>  array(
                array(
                    'tag'       =>  'div',
                    'style'     =>  'width:100%; height: 20px; background: red;',
                    'text'      =>  'Child DIV node with style attribute',
                ),
                array(
                    'tag'       =>  'div',
                    'style'     =>  'width:100%; height: 30px; background: blue;',
                    'text'      =>  'Child DIV node with style attribute',
                ),
            )
        )
    );
    
    echo $html->getHtml();

?>