PHP Classes

Dynamic HTML: Generate HTML documents programmatically

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 321 All time: 7,224 This week: 455Up
Version License PHP version Categories
dynamic-html 0.1GNU General Publi...5HTML, XML, PHP 5, Tools, Text processing, T..., P...


This package can generate HTML documents programmatically.

It provides base classes to output HTML tags by calling static functions that take parameters and generate HTML tags from those parameters.

The classes can be extended to support other tags not yet supported.

Picture of Joshua McKenzie
  Performance   Level  
Name: Joshua McKenzie <contact>
Classes: 2 packages by
Country: United States United States
Age: ???
All time rank: 3247435 in United States United States
Week rank: 264 Up31 in United States United States Up



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)`

  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file Doc. Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageDynamicHtml (3 files)

  Files folder image Files  /  src  /  DynamicHtml  
File Role Description
  Plain text file DynamicTags.php Class Class source
  Plain text file DynamicTagsHelper.php Class Class source
  Plain text file DynamicTagsShort.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:7,224
This week:455Up