PHP Classes


Recommend this page to a friend!
  Classes of Joshua McKenzie   Dynamic HTML   Download  
Role: Documentation
Content type: text/markdown
Description: Auxiliary data
Class: Dynamic HTML
Generate HTML documents programmatically
Author: By
Last change: v2 docs
Date: 7 years ago
Size: 4,125 bytes


Class file image Download


An extensible and dynamic HTML helper library for PHP


The new version includes some cleaner approaches and more logical interfaces. The changes are as follows: - Removed auto echo setting: It seemed to only complicate what should be simple, so I removed this. Storage and output methods can be approached from the custom user app itself. - Added DynamicTags::mergeAttr(): Converts & merges passed arrays. Especially useful for extending. See examples below. - Changed DynamicTags::attrArrayToStr() to DynamicTags::createAttrString() and added support for param string as well as array - Added mapColsArr(), mapCols(), mapRowsArr(), and mapRows() See docs below


This library, and it's classes, are fairly straight-forward. The encouragement is to extend with your own tags/methods, for others to use, and for your own projects.

The initial motivation was to further divide server-side code from client-side code. A furthering motivation was to provide an extensible interface for script-to-HTML mapping in the most basic of forms, saving us from messy(and slow) code.


Via Composer

composer require iautomation/dynamic-html

and include composer if needed

include './vendor/autoload.php'


Include the class files from the src directory

Example Usage

Basic Example

Below is a full html document written completely with DynamicTags


use \DynamicHtml\DynamicTags as DT;
use \DynamicHtml\DynamicTagsShort as DTS;
use \DynamicHtml\DynamicTagsHelper as DTH;

echo DT::create('!DOCTYPE', 'html', null);
echo DT::html();

echo DT::head();
	echo DT::base('href='); // or echo DT::base(['href'=>'', 'id'=>'blah']);
	echo DT::meta('name=description&content=This is the description');
echo DT::end();

echo DT::body();

echo DT::header();
echo DT::ul();
echo DT::li(null, DTH::hyperlink('http://...', null, 'one'));
echo DT::li(null, DTH::hyperlink('http://...', null, 'two'));
echo DT::li(null, DTH::hyperlink('http://...', null, 'three'));
echo DT::end(2);

echo DTH::table([
	['1', '2', '3'],
	['2', '3', '1'],

echo DT::style();
echo <<<EOT
[testselector] {
	background: blue;
echo DT::end();
echo DT::div('testselector', 'hi');

echo DT::endAll();


Below is specific documentation to each class, it's methods, and example usage.


The main class providing methods to convert attributes, create start and end tags, and record/output end tags using the end() method.

Example Usage

use \DynamicHtml\DynamicTags as DT;

echo DT::span('id=name', 'John Doe'); // or
echo DT::span(['id'=>'name'], 'John Doe'); // or
echo DT::span('id=name').'John Doe'.DT::end();


  • `__callStatic($method, $args)`
  • `create($name, $attr=null, $content=true)`
  • `end($amount=1)`
  • `endAll()`
  • `createStartTag($name, $attr=null)`
  • `createEndTag($name)`
  • `addTagToLog($name)`
  • `removeTagFromLog()`
  • `mergeAttr()`
  • `createAttrString($attr=null)`
  • `mapColsArr($method, $columns)`
  • `mapCols($method)`
  • `mapRowsArr($method, $rows)`
  • `mapRows($method)`


A helper to accessing DynamicTags, only with the short tag configured(by setting $content to false)

Example Usage

use \DynamicHtml\DynamicTagsShort as DTS;

echo DTS::br();
// without this class, we'd have to type:
// echo DT::br(null, false);


  • `__callStatic($method, $args)`


Lastly, we have the a helper class, though useful, can also be seen as an example class. Provides a showcase of methods extending DynamicTags.

Example Usage

use \DynamicHtml\DynamicTagsHelper as DTH;

echo DTH::hyperlink('http://...', null, 'one');
echo DTH::table([
	['1', '2', '3'],
	['2', '3', '1'],


  • `stylesheet($href, $attr=null)`
  • `hyperlink($href, $attr=null, $content=true)`
  • `table($body_rows, $head_fields=null)`
  • `tableHead($fields)`
  • `tableHeadRow($fields)`
  • `tableBody($rows)`
  • `tableBodyRow($fields)`