2017 © Pedro Peláez
 

php-class simple-html-element

Handle HTML elements as an object with optional nodes

image

derxen/simple-html-element

Handle HTML elements as an object with optional nodes

  • Wednesday, May 4, 2016
  • by derxen
  • Repository
  • 1 Watchers
  • 1 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SimpleHtmlElement

Handle HTML elements as an object with optional nodes, (*1)

Installation

Composer

You can use SimpleHtmlElement by putting the following line into your composer.json, (*2)

    {
        "require": {
            "derxen/simple-html-element": "~1.0"
        }
    }

And make sure you load the class within you PHP code or use the Composer Autoloader, (*3)

Documentation

SimpleHtmlElement has been made to make your work easier. Here is an example:, (*4)

Create html root., (*5)

$html       = new derxen\SimpleHtmlElement();

We define some table headers., (*6)

$headers    = ['publish date', 'title', 'author'];

We fetch some table data., (*7)

$data       = [];
$data[]     = ['05-03-2016', 'A great book', 'Sam Wilson'];
$data[]     = ['08-04-2016', 'Another great book', 'Jane Fisscher'];
$data[]     = ['11-01-2016', 'The greatest book', 'Dan Morris'];

Let us create a new table. If you give an array as property, SimpleHtmlElement will handle the property as attributes, (*8)

$table      = $html->table(['method' => 'post']);

Now we add the table headers., (*9)

foreach($headers as $th) {
    $table->th($th);
}

Now we add the table rows with content. If you give a string as property, SimpleHtmlElement will handle the property as content, (*10)

foreach($data as $cols) {
    $tr = $table->tr();
    foreach($cols as $td) {
        $tr->td($td);
    }
}

We could set some extra attributes to the table., (*11)

$table->setAttribute(['action' => '/handleform']);

Our table is ready. Now we render the table, (*12)

echo $table->write();

Or We can just do:, (*13)

echo $table;

The Versions

04/05 2016

dev-master

9999999-dev

Handle HTML elements as an object with optional nodes

  Sources   Download

GPL-3.0

The Requires

  • php >=5.2.0