Download the PHP package fischimglas/ptag without Composer
On this page you can find all versions of the php package fischimglas/ptag. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fischimglas/ptag
More information about fischimglas/ptag
Files in fischimglas/ptag
Package ptag
Short Description PHP HTML abstraction, Create html elements
License MIT
Homepage https://github.com/fischimglas/PTag
Informations about the package ptag
PTag
PHP HTML abstraction, Create html elements
Installation
composer require fischimglas/ptag
Usage
- Create any HTML element with
HtmlFactory::<tagName>($attributes, $childContent)
- Add
$element->addClass($className)
and remove$element->removeClass($className)
css classes - Set
$element->setAttribute($attrName,$attrValue)
and remove$element->removeAttribute($attrName)
attributes - Set
$element->setStyle($attrName,$attrValue)
and remove$element->removeStyle($attrName)
attributes - Add attributes with no value
$element->setAttribute($attrName)
- Clone elements
$element->clone()
- Chain modifications
$element->clone()->add($anyContent)->addClass('test')
Basic example
Result:
<div class="first-class" tabindex="1" uk-img style="background:red"><a href="#">Link</a><img src="image.png"></div>
Empty container
If no html tag is defined, the element can be used as empty container. Attributes and classes to the empty container are ignored.
Result:
Some content<a href="#">Link</a>
Configure mode (HTML5 / XHTML)
By default, HTML5 is assumed and trailing slashes on void elements are avoided. For XHTML,
use ElementCf::setMode(ElementCf::MODE_XHML);
to require trailing slashes.
Result:
<div><img src="image.png" /></div>
All versions of ptag with dependencies
ext-json Version *