class HTML (View source)

A class that serves as a fluent interface to write HTML in PHP. It also helps with creating HTML elements on the fly.

Example:

// return an HTML element by using some tag name as a static method
// "div" can be replaced by any other valid HTML element tag name
$html = HTML::div('This is a div!', ['class' => 'container']);

// create elements using "->element()" or "->{$tagName}()"
// create entities using "->entity()"
// create comments using "->comment()"
// structure deeply nested elements using "->open()" and "->close()" (wrapping methods)
// make the next action conditional using "->condition()" or "->if()"
// execute some logic (loops, complex if-statements) while creating the HTML using "->function()" or "->do()"
// retrieve the final generated HTML by using "->render()"
(new HTML())
    ->element('h1', 'HTML Forms', ['class' => 'title'])
    ->open('form', ['method' => 'POST'])
        ->comment('SIMPLE FORM')
        ->h2('Example', ['class' => 'subtitle'])
        ->p('This is an example form.')
        ->br()
        ->if(isset($variable))->div('$variable is set')
        ->open('fieldset')
            ->legend('Form 1', ['style' => 'color: #333;'])
            ->label('Message: ', ['class' => 'text'])
            ->input(['type' => 'text', 'required'])
            ->entity('nbsp')
            ->input(['type' => 'submit', 'value' => 'Submit'])
        ->close()
        ->open('ul', ['class' => 'errors'])
            ->do(function () {
                foreach (['Error 1', 'Error 2', 'Error 3'] as $error) {
                    $this->li($error);
                }
            })
        ->close()
    ->close()
->render();

Constants

TAGS

HTML tags.

protected TAG_CLOSING

Closing tag.

protected TAG_NORMAL

Normal tag.

protected TAG_OPENING

Opening tag.

Properties

protected array $buffer

Current buffer.

protected array $conditions

Conditions track.

protected array $stack

Current stack (nesting).

Methods

mixed
__call(string $name, array $arguments)

Makes HTML tags available as methods on the class.

static mixed
__callStatic(string $name, array $arguments)

Makes HTML tags available as static methods on the class.

__construct(bool $strict = false, bool $indent = true)

HTML constructor.

string
__toString()

Returns the current HTML buffer.

static string
a(mixed $content = '', array $attributes = [])

Defines a hyperlink.

static string
abbr(mixed $content = '', array $attributes = [])

Defines an abbreviation or an acronym.

static string
acronym(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <abbr> instead. Defines an acronym.

static string
address(mixed $content = '', array $attributes = [])

Defines contact information for the author/owner of a document.

static string
applet(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <embed> or <object> instead. Defines an embedded applet.

static string
area(array $attributes = [])

Defines an area inside an image map.

static string
article(mixed $content = '', array $attributes = [])

Defines an article.

static string
aside(mixed $content = '', array $attributes = [])

Defines content aside from the page content.

void
assert(bool $condition, string $message)

Checks if the passed condition and throws exception if it's not truthy.

static string
audio(mixed $content = '', array $attributes = [])

Defines embedded sound content.

static string
b(mixed $content = '', array $attributes = [])

Defines bold text.

static string
base(array $attributes = [])

Specifies the base URL/target for all relative URLs in a document.

static string
basefont(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Specifies a default color, size, and font for all text in a document.

static string
bdi(mixed $content = '', array $attributes = [])

Isolates a part of text that might be formatted in a different direction from other text outside it.

static string
bdo(mixed $content = '', array $attributes = [])

Overrides the current text direction.

static string
big(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines big text.

static string
blockquote(mixed $content = '', array $attributes = [])

Defines a section that is quoted from another source.

static string
body(mixed $content = '', array $attributes = [])

Defines the document's body.

static string
br(array $attributes = [])

Defines a single line break.

static string
button(mixed $content = '', array $attributes = [])

Defines a clickable button.

static string
canvas(mixed $content = '', array $attributes = [])

Used to draw graphics, on the fly, via scripting (usually JavaScript).

static string
caption(mixed $content = '', array $attributes = [])

Defines a table caption.

static string
center(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines centered text.

static string
cite(mixed $content = '', array $attributes = [])

Defines the title of a work.

close()

Creates an HTML closing tag matching the last tag opened by self::open().

static string
code(mixed $content = '', array $attributes = [])

Defines a piece of computer code.

static string
col(array $attributes = [])

Specifies column properties for each column within a <colgroup> element.

static string
colgroup(mixed $content = '', array $attributes = [])

Specifies a group of one or more columns in a table for formatting.

comment(string $text)

Creates an HTML comment from the specified text and pass it to the buffer.

condition(mixed $condition)

Takes a condition (some boolean value) to determine whether or not to create the very next element and pass it to the buffer.

static string
data(mixed $content = '', array $attributes = [])

Adds a machine-readable translation of a given content.

static string
datalist(mixed $content = '', array $attributes = [])

Specifies a list of pre-defined options for input controls.

static string
dd(mixed $content = '', array $attributes = [])

Defines a description/value of a term in a description list.

static string
del(mixed $content = '', array $attributes = [])

Defines text that has been deleted from a document.

static string
details(mixed $content = '', array $attributes = [])

Defines additional details that the user can view or hide.

static string
dfn(mixed $content = '', array $attributes = [])

Specifies a term that is going to be defined within the content.

static string
dialog(mixed $content = '', array $attributes = [])

Defines a dialog box or window.

static string
dir(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <ul> instead. Defines a directory list.

static string
div(mixed $content = '', array $attributes = [])

Defines a section in a document.

static string
dl(mixed $content = '', array $attributes = [])

Defines a description list.

do(callable $callback)

Alias for self::function(). See the corresponding method for more details.

static string
dt(mixed $content = '', array $attributes = [])

Defines a term/name in a description list.

element(string $name, mixed $content = '', array $attributes = [])

Creates a complete HTML element (opening and closing tags) constructed from the specified parameters and pass it to the buffer.

static string
em(mixed $content = '', array $attributes = [])

Defines emphasized text.

static string
embed(array $attributes = [])

Defines a container for an external application.

entity(string $name)

Creates an HTML entity from the specified name and pass it to the buffer.

static string
fieldset(mixed $content = '', array $attributes = [])

Groups related elements in a form.

static string
figcaption(mixed $content = '', array $attributes = [])

Defines a caption for a <figure> element.

static string
figure(mixed $content = '', array $attributes = [])

Specifies self-contained content.

static string
font(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines font, color, and size for text.

static string
footer(mixed $content = '', array $attributes = [])

Defines a footer for a document or section.

static string
form(mixed $content = '', array $attributes = [])

Defines an HTML form for user input.

static string
frame(mixed $content = '', array $attributes = [])

Not supported in HTML5. Defines a window (a frame) in a frameset.

static string
frameset(mixed $content = '', array $attributes = [])

Not supported in HTML5. Defines a set of frames.

function(callable $callback)

Takes a callback and executes it after binding $this (HTML) to it, useful for example to execute any PHP code while creating the markup.

static string
h1(mixed $content = '', array $attributes = [])

Defines HTML heading.

static string
h2(mixed $content = '', array $attributes = [])

Defines HTML heading.

static string
h3(mixed $content = '', array $attributes = [])

Defines HTML heading.

static string
h4(mixed $content = '', array $attributes = [])

Defines HTML heading.

static string
h5(mixed $content = '', array $attributes = [])

Defines HTML heading.

static string
h6(mixed $content = '', array $attributes = [])

Defines HTML heading.

static string
head(mixed $content = '', array $attributes = [])

Contains metadata/information for the document.

static string
header(mixed $content = '', array $attributes = [])

Defines a header for a document or section.

static string
hr(array $attributes = [])

Defines a thematic change in the content.

static string
html(mixed $content = '', array $attributes = [])

Defines the root of an HTML document.

static string
i(mixed $content = '', array $attributes = [])

Defines a part of text in an alternate voice or mood.

if(mixed $condition)

Alias for self::condition(). See the corresponding method for more details.

static string
iframe(mixed $content = '', array $attributes = [])

Defines an inline frame.

static string
img(array $attributes = [])

Defines an image.

static string
input(array $attributes = [])

Defines an input control.

static string
ins(mixed $content = '', array $attributes = [])

Defines a text that has been inserted into a document.

string
interpolate(string $text, array $variables = [])

Replaces variables in the passed string with values from the passed variables.

bool
isConditionTruthy(int $depth = self::TAG_NORMAL)

Determines whether or not the last set condition is truthy or falsy.

static string
kbd(mixed $content = '', array $attributes = [])

Defines keyboard input.

static string
label(mixed $content = '', array $attributes = [])

Defines a label for an <input> element.

static string
legend(mixed $content = '', array $attributes = [])

Defines a caption for a <fieldset> element.

static string
li(mixed $content = '', array $attributes = [])

Defines a list item.

static string
link(array $attributes = [])

Defines the relationship between a document and an external resource (most used to link to style sheets).

static string
main(mixed $content = '', array $attributes = [])

Specifies the main content of a document.

static string
map(mixed $content = '', array $attributes = [])

Defines an image map.

static string
mark(mixed $content = '', array $attributes = [])

Defines marked/highlighted text.

static string
meta(array $attributes = [])

Defines metadata about an HTML document.

static string
meter(mixed $content = '', array $attributes = [])

Defines a scalar measurement within a known range (a gauge).

static string
minify(string $html)

Minifies HTML buffers by removing all unnecessary whitespaces and comments.

static string
nav(mixed $content = '', array $attributes = [])

Defines navigation links.

node(string $text)

Creates an arbitrary text-node from the specified text and pass it to the buffer (useful to add some special tags, "<!DOCTYPE html>" for example).

static string
noframes(mixed $content = '', array $attributes = [])

Not supported in HTML5. Defines an alternate content for users that do not support frames.

string
normalizeTagName(string $name)

Returns a normalized HTML tag name from the specified name.

static string
noscript(mixed $content = '', array $attributes = [])

Defines an alternate content for users that do not support client-side scripts.

static string
object(mixed $content = '', array $attributes = [])

Defines a container for an external application.

static string
ol(mixed $content = '', array $attributes = [])

Defines an ordered list.

open(string $name, array $attributes = [])

Creates an HTML opening tag from the specified parameters and pass it to the buffer. Works in conjunction with self::close().

static string
optgroup(mixed $content = '', array $attributes = [])

Defines a group of related options in a drop-down list.

static string
option(mixed $content = '', array $attributes = [])

Defines an option in a drop-down list.

static string
output(mixed $content = '', array $attributes = [])

Defines the result of a calculation.

static string
p(mixed $content = '', array $attributes = [])

Defines a paragraph.

static string
param(array $attributes = [])

Defines a parameter for an object.

static string
picture(mixed $content = '', array $attributes = [])

Defines a container for multiple image resources.

static string
pre(mixed $content = '', array $attributes = [])

Defines preformatted text.

static string
progress(mixed $content = '', array $attributes = [])

Represents the progress of a task.

static string
q(mixed $content = '', array $attributes = [])

Defines a short quotation.

string
render()

Returns the created HTML elements found in the buffer and empties it.

static string
rp(mixed $content = '', array $attributes = [])

Defines what to show in browsers that do not support ruby annotations.

static string
rt(mixed $content = '', array $attributes = [])

Defines an explanation/pronunciation of characters (for East Asian typography).

static string
ruby(mixed $content = '', array $attributes = [])

Defines a ruby annotation (for East Asian typography).

static string
s(mixed $content = '', array $attributes = [])

Defines text that is no longer correct.

static string
samp(mixed $content = '', array $attributes = [])

Defines sample output from a computer program.

static string
script(mixed $content = '', array $attributes = [])

Defines a client-side script.

static string
section(mixed $content = '', array $attributes = [])

Defines a section in a document.

static string
select(mixed $content = '', array $attributes = [])

Defines a drop-down list.

static string
small(mixed $content = '', array $attributes = [])

Defines smaller text.

static string
source(array $attributes = [])

Defines multiple media resources for media elements (<video> and <audio>).

static string
span(mixed $content = '', array $attributes = [])

Defines a section in a document.

static string
strike(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <del> or <s> instead. Defines strikethrough text.

string
stringifyAttributes(array $attributes)

Returns an HTML attributes string from an associative array of attributes.

static string
strong(mixed $content = '', array $attributes = [])

Defines important text.

static string
style(mixed $content = '', array $attributes = [])

Defines style information for a document.

static string
sub(mixed $content = '', array $attributes = [])

Defines subscripted text.

static string
summary(mixed $content = '', array $attributes = [])

Defines a visible heading for a <details> element.

static string
sup(mixed $content = '', array $attributes = [])

Defines superscripted text.

static string
svg(mixed $content = '', array $attributes = [])

Defines a container for SVG graphics.

static string
table(mixed $content = '', array $attributes = [])

Defines a table.

static string
tbody(mixed $content = '', array $attributes = [])

Groups the body content in a table.

static string
td(mixed $content = '', array $attributes = [])

Defines a cell in a table.

static string
template(mixed $content = '', array $attributes = [])

Defines a container for content that should be hidden when the page loads.

static string
textarea(mixed $content = '', array $attributes = [])

Defines a multiline input control (text area).

static string
tfoot(mixed $content = '', array $attributes = [])

Groups the footer content in a table.

static string
th(mixed $content = '', array $attributes = [])

Defines a header cell in a table.

static string
thead(mixed $content = '', array $attributes = [])

Groups the header content in a table.

static string
time(mixed $content = '', array $attributes = [])

Defines a specific time (or datetime).

static string
title(mixed $content = '', array $attributes = [])

Defines a title for the document.

static string
tr(mixed $content = '', array $attributes = [])

Defines a row in a table.

static string
track(array $attributes = [])

Defines text tracks for media elements (<video> and <audio>).

static string
tt(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines teletype text.

static string
u(mixed $content = '', array $attributes = [])

Defines some text that is unarticulated and styled differently from normal text.

static string
ul(mixed $content = '', array $attributes = [])

Defines an unordered list.

static void
validate(string $html)

Asserts that the passed HTML is valid.

static string
var(mixed $content = '', array $attributes = [])

Defines a variable.

static string
video(mixed $content = '', array $attributes = [])

Defines embedded video content.

static string
wbr(array $attributes = [])

Defines a possible line-break.

write(string $content)

Writes content to the HTML buffer.

Details

mixed __call(string $name, array $arguments)

Makes HTML tags available as methods on the class.

Parameters

string $name
array $arguments

Return Value

mixed

static mixed __callStatic(string $name, array $arguments)

Makes HTML tags available as static methods on the class.

Parameters

string $name
array $arguments

Return Value

mixed

__construct(bool $strict = false, bool $indent = true)

HTML constructor.

Parameters

bool $strict

Whether to validate the generated HTML upon return or not.

bool $indent

Whether to indent the generated HTML or not.

string __toString()

Returns the current HTML buffer.

Return Value

string

static string a(mixed $content = '', array $attributes = [])

Defines a hyperlink.

Parameters

mixed $content
array $attributes

Return Value

string

static string abbr(mixed $content = '', array $attributes = [])

Defines an abbreviation or an acronym.

Parameters

mixed $content
array $attributes

Return Value

string

static string acronym(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <abbr> instead. Defines an acronym.

Parameters

mixed $content
array $attributes

Return Value

string

static string address(mixed $content = '', array $attributes = [])

Defines contact information for the author/owner of a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string applet(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <embed> or <object> instead. Defines an embedded applet.

Parameters

mixed $content
array $attributes

Return Value

string

static string area(array $attributes = [])

Defines an area inside an image map.

Parameters

array $attributes

Return Value

string

static string article(mixed $content = '', array $attributes = [])

Defines an article.

Parameters

mixed $content
array $attributes

Return Value

string

static string aside(mixed $content = '', array $attributes = [])

Defines content aside from the page content.

Parameters

mixed $content
array $attributes

Return Value

string

private void assert(bool $condition, string $message)

Checks if the passed condition and throws exception if it's not truthy.

The message that is passed to this function should contain four %s placeholders for the class, function, file and line of the previous caller (offset 1 of the backtrace).

Parameters

bool $condition
string $message

Return Value

void

Exceptions

Exception

static string audio(mixed $content = '', array $attributes = [])

Defines embedded sound content.

Parameters

mixed $content
array $attributes

Return Value

string

static string b(mixed $content = '', array $attributes = [])

Defines bold text.

Parameters

mixed $content
array $attributes

Return Value

string

static string base(array $attributes = [])

Specifies the base URL/target for all relative URLs in a document.

Parameters

array $attributes

Return Value

string

static string basefont(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Specifies a default color, size, and font for all text in a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string bdi(mixed $content = '', array $attributes = [])

Isolates a part of text that might be formatted in a different direction from other text outside it.

Parameters

mixed $content
array $attributes

Return Value

string

static string bdo(mixed $content = '', array $attributes = [])

Overrides the current text direction.

Parameters

mixed $content
array $attributes

Return Value

string

static string big(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines big text.

Parameters

mixed $content
array $attributes

Return Value

string

static string blockquote(mixed $content = '', array $attributes = [])

Defines a section that is quoted from another source.

Parameters

mixed $content
array $attributes

Return Value

string

static string body(mixed $content = '', array $attributes = [])

Defines the document's body.

Parameters

mixed $content
array $attributes

Return Value

string

static string br(array $attributes = [])

Defines a single line break.

Parameters

array $attributes

Return Value

string

static string button(mixed $content = '', array $attributes = [])

Defines a clickable button.

Parameters

mixed $content
array $attributes

Return Value

string

static string canvas(mixed $content = '', array $attributes = [])

Used to draw graphics, on the fly, via scripting (usually JavaScript).

Parameters

mixed $content
array $attributes

Return Value

string

static string caption(mixed $content = '', array $attributes = [])

Defines a table caption.

Parameters

mixed $content
array $attributes

Return Value

string

static string center(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines centered text.

Parameters

mixed $content
array $attributes

Return Value

string

static string cite(mixed $content = '', array $attributes = [])

Defines the title of a work.

Parameters

mixed $content
array $attributes

Return Value

string

HTML close()

Creates an HTML closing tag matching the last tag opened by self::open().

Return Value

HTML

Exceptions

Exception

static string code(mixed $content = '', array $attributes = [])

Defines a piece of computer code.

Parameters

mixed $content
array $attributes

Return Value

string

static string col(array $attributes = [])

Specifies column properties for each column within a <colgroup> element.

Parameters

array $attributes

Return Value

string

static string colgroup(mixed $content = '', array $attributes = [])

Specifies a group of one or more columns in a table for formatting.

Parameters

mixed $content
array $attributes

Return Value

string

HTML comment(string $text)

Creates an HTML comment from the specified text and pass it to the buffer.

Parameters

string $text

The text content of the HTML comment without <!-- and -->.

Return Value

HTML

Exceptions

Exception

HTML condition(mixed $condition)

Takes a condition (some boolean value) to determine whether or not to create the very next element and pass it to the buffer.

Parameters

mixed $condition

Any value that can be casted to a boolean.

Return Value

HTML

static string data(mixed $content = '', array $attributes = [])

Adds a machine-readable translation of a given content.

Parameters

mixed $content
array $attributes

Return Value

string

static string datalist(mixed $content = '', array $attributes = [])

Specifies a list of pre-defined options for input controls.

Parameters

mixed $content
array $attributes

Return Value

string

static string dd(mixed $content = '', array $attributes = [])

Defines a description/value of a term in a description list.

Parameters

mixed $content
array $attributes

Return Value

string

static string del(mixed $content = '', array $attributes = [])

Defines text that has been deleted from a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string details(mixed $content = '', array $attributes = [])

Defines additional details that the user can view or hide.

Parameters

mixed $content
array $attributes

Return Value

string

static string dfn(mixed $content = '', array $attributes = [])

Specifies a term that is going to be defined within the content.

Parameters

mixed $content
array $attributes

Return Value

string

static string dialog(mixed $content = '', array $attributes = [])

Defines a dialog box or window.

Parameters

mixed $content
array $attributes

Return Value

string

static string dir(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <ul> instead. Defines a directory list.

Parameters

mixed $content
array $attributes

Return Value

string

static string div(mixed $content = '', array $attributes = [])

Defines a section in a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string dl(mixed $content = '', array $attributes = [])

Defines a description list.

Parameters

mixed $content
array $attributes

Return Value

string

HTML do(callable $callback)

Alias for self::function(). See the corresponding method for more details.

Parameters

callable $callback

Return Value

HTML

static string dt(mixed $content = '', array $attributes = [])

Defines a term/name in a description list.

Parameters

mixed $content
array $attributes

Return Value

string

HTML element(string $name, mixed $content = '', array $attributes = [])

Creates a complete HTML element (opening and closing tags) constructed from the specified parameters and pass it to the buffer.

Parameters

string $name

The name of the HTML tag.

mixed $content

[optional] The textual or HTML content of the element (preferably scalar), passing null will make the tag a self-closing tag, all other types will simply get stringified (arrays and objects as JSON).

array $attributes

[optional] An associative array of attributes. To indicate a boolean-attribute (no-value-attribute), simply provide a key with value null or provide only a value as the name of the attribute without a key. As a shortcut, setting the value as false will exclude the attribute.

Return Value

HTML

Exceptions

Exception

static string em(mixed $content = '', array $attributes = [])

Defines emphasized text.

Parameters

mixed $content
array $attributes

Return Value

string

static string embed(array $attributes = [])

Defines a container for an external application.

Parameters

array $attributes

Return Value

string

HTML entity(string $name)

Creates an HTML entity from the specified name and pass it to the buffer.

Parameters

string $name

The name of the HTML entity without & nor ;.

Return Value

HTML

Exceptions

Exception

static string fieldset(mixed $content = '', array $attributes = [])

Groups related elements in a form.

Parameters

mixed $content
array $attributes

Return Value

string

static string figcaption(mixed $content = '', array $attributes = [])

Defines a caption for a <figure> element.

Parameters

mixed $content
array $attributes

Return Value

string

static string figure(mixed $content = '', array $attributes = [])

Specifies self-contained content.

Parameters

mixed $content
array $attributes

Return Value

string

static string font(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines font, color, and size for text.

Parameters

mixed $content
array $attributes

Return Value

string

Defines a footer for a document or section.

Parameters

mixed $content
array $attributes

Return Value

string

static string form(mixed $content = '', array $attributes = [])

Defines an HTML form for user input.

Parameters

mixed $content
array $attributes

Return Value

string

static string frame(mixed $content = '', array $attributes = [])

Not supported in HTML5. Defines a window (a frame) in a frameset.

Parameters

mixed $content
array $attributes

Return Value

string

static string frameset(mixed $content = '', array $attributes = [])

Not supported in HTML5. Defines a set of frames.

Parameters

mixed $content
array $attributes

Return Value

string

HTML function(callable $callback)

Takes a callback and executes it after binding $this (HTML) to it, useful for example to execute any PHP code while creating the markup.

Parameters

callable $callback

The callback to call and bind $this to, this callback will also be passed the instance it was called on as the first parameter.

Return Value

HTML

static string h1(mixed $content = '', array $attributes = [])

Defines HTML heading.

Parameters

mixed $content
array $attributes

Return Value

string

static string h2(mixed $content = '', array $attributes = [])

Defines HTML heading.

Parameters

mixed $content
array $attributes

Return Value

string

static string h3(mixed $content = '', array $attributes = [])

Defines HTML heading.

Parameters

mixed $content
array $attributes

Return Value

string

static string h4(mixed $content = '', array $attributes = [])

Defines HTML heading.

Parameters

mixed $content
array $attributes

Return Value

string

static string h5(mixed $content = '', array $attributes = [])

Defines HTML heading.

Parameters

mixed $content
array $attributes

Return Value

string

static string h6(mixed $content = '', array $attributes = [])

Defines HTML heading.

Parameters

mixed $content
array $attributes

Return Value

string

static string head(mixed $content = '', array $attributes = [])

Contains metadata/information for the document.

Parameters

mixed $content
array $attributes

Return Value

string

static string header(mixed $content = '', array $attributes = [])

Defines a header for a document or section.

Parameters

mixed $content
array $attributes

Return Value

string

static string hr(array $attributes = [])

Defines a thematic change in the content.

Parameters

array $attributes

Return Value

string

static string html(mixed $content = '', array $attributes = [])

Defines the root of an HTML document.

Parameters

mixed $content
array $attributes

Return Value

string

static string i(mixed $content = '', array $attributes = [])

Defines a part of text in an alternate voice or mood.

Parameters

mixed $content
array $attributes

Return Value

string

HTML if(mixed $condition)

Alias for self::condition(). See the corresponding method for more details.

Parameters

mixed $condition

Return Value

HTML

static string iframe(mixed $content = '', array $attributes = [])

Defines an inline frame.

Parameters

mixed $content
array $attributes

Return Value

string

static string img(array $attributes = [])

Defines an image.

Parameters

array $attributes

Return Value

string

static string input(array $attributes = [])

Defines an input control.

Parameters

array $attributes

Return Value

string

static string ins(mixed $content = '', array $attributes = [])

Defines a text that has been inserted into a document.

Parameters

mixed $content
array $attributes

Return Value

string

private string interpolate(string $text, array $variables = [])

Replaces variables in the passed string with values from the passed variables.

Parameters

string $text

A string like {var} Element.

array $variables

An associative array like ['var' => 'HTML'].

Return Value

string

A string like HTML Element

protected bool isConditionTruthy(int $depth = self::TAG_NORMAL)

Determines whether or not the last set condition is truthy or falsy.

Parameters

int $depth

[optional] A flag to indicate condition depth [+1 = opened, 0 = normal, -1 = closed].

Return Value

bool

The result of the current condition.

static string kbd(mixed $content = '', array $attributes = [])

Defines keyboard input.

Parameters

mixed $content
array $attributes

Return Value

string

static string label(mixed $content = '', array $attributes = [])

Defines a label for an <input> element.

Parameters

mixed $content
array $attributes

Return Value

string

static string legend(mixed $content = '', array $attributes = [])

Defines a caption for a <fieldset> element.

Parameters

mixed $content
array $attributes

Return Value

string

static string li(mixed $content = '', array $attributes = [])

Defines a list item.

Parameters

mixed $content
array $attributes

Return Value

string

Defines the relationship between a document and an external resource (most used to link to style sheets).

Parameters

array $attributes

Return Value

string

static string main(mixed $content = '', array $attributes = [])

Specifies the main content of a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string map(mixed $content = '', array $attributes = [])

Defines an image map.

Parameters

mixed $content
array $attributes

Return Value

string

static string mark(mixed $content = '', array $attributes = [])

Defines marked/highlighted text.

Parameters

mixed $content
array $attributes

Return Value

string

static string meta(array $attributes = [])

Defines metadata about an HTML document.

Parameters

array $attributes

Return Value

string

static string meter(mixed $content = '', array $attributes = [])

Defines a scalar measurement within a known range (a gauge).

Parameters

mixed $content
array $attributes

Return Value

string

static string minify(string $html)

Minifies HTML buffers by removing all unnecessary whitespaces and comments.

Parameters

string $html

Return Value

string

static string nav(mixed $content = '', array $attributes = [])

Defines navigation links.

Parameters

mixed $content
array $attributes

Return Value

string

HTML node(string $text)

Creates an arbitrary text-node from the specified text and pass it to the buffer (useful to add some special tags, "<!DOCTYPE html>" for example).

Parameters

string $text

The text to add to the buffer.

Return Value

HTML

Exceptions

Exception

static string noframes(mixed $content = '', array $attributes = [])

Not supported in HTML5. Defines an alternate content for users that do not support frames.

Parameters

mixed $content
array $attributes

Return Value

string

protected string normalizeTagName(string $name)

Returns a normalized HTML tag name from the specified name.

Parameters

string $name

The name of the tag.

Return Value

string

static string noscript(mixed $content = '', array $attributes = [])

Defines an alternate content for users that do not support client-side scripts.

Parameters

mixed $content
array $attributes

Return Value

string

static string object(mixed $content = '', array $attributes = [])

Defines a container for an external application.

Parameters

mixed $content
array $attributes

Return Value

string

static string ol(mixed $content = '', array $attributes = [])

Defines an ordered list.

Parameters

mixed $content
array $attributes

Return Value

string

HTML open(string $name, array $attributes = [])

Creates an HTML opening tag from the specified parameters and pass it to the buffer. Works in conjunction with self::close().

Parameters

string $name

A name of an HTML tag.

array $attributes

[optional] An associative array of attributes. To indicate a boolean-attribute (no-value-attribute), simply provide a key with value null. Setting the value as false will exclude the attribute.

Return Value

HTML

Exceptions

Exception

static string optgroup(mixed $content = '', array $attributes = [])

Defines a group of related options in a drop-down list.

Parameters

mixed $content
array $attributes

Return Value

string

static string option(mixed $content = '', array $attributes = [])

Defines an option in a drop-down list.

Parameters

mixed $content
array $attributes

Return Value

string

static string output(mixed $content = '', array $attributes = [])

Defines the result of a calculation.

Parameters

mixed $content
array $attributes

Return Value

string

static string p(mixed $content = '', array $attributes = [])

Defines a paragraph.

Parameters

mixed $content
array $attributes

Return Value

string

static string param(array $attributes = [])

Defines a parameter for an object.

Parameters

array $attributes

Return Value

string

static string picture(mixed $content = '', array $attributes = [])

Defines a container for multiple image resources.

Parameters

mixed $content
array $attributes

Return Value

string

static string pre(mixed $content = '', array $attributes = [])

Defines preformatted text.

Parameters

mixed $content
array $attributes

Return Value

string

static string progress(mixed $content = '', array $attributes = [])

Represents the progress of a task.

Parameters

mixed $content
array $attributes

Return Value

string

static string q(mixed $content = '', array $attributes = [])

Defines a short quotation.

Parameters

mixed $content
array $attributes

Return Value

string

string render()

Returns the created HTML elements found in the buffer and empties it.

Return Value

string

Exceptions

Exception
Exception

static string rp(mixed $content = '', array $attributes = [])

Defines what to show in browsers that do not support ruby annotations.

Parameters

mixed $content
array $attributes

Return Value

string

static string rt(mixed $content = '', array $attributes = [])

Defines an explanation/pronunciation of characters (for East Asian typography).

Parameters

mixed $content
array $attributes

Return Value

string

static string ruby(mixed $content = '', array $attributes = [])

Defines a ruby annotation (for East Asian typography).

Parameters

mixed $content
array $attributes

Return Value

string

static string s(mixed $content = '', array $attributes = [])

Defines text that is no longer correct.

Parameters

mixed $content
array $attributes

Return Value

string

static string samp(mixed $content = '', array $attributes = [])

Defines sample output from a computer program.

Parameters

mixed $content
array $attributes

Return Value

string

static string script(mixed $content = '', array $attributes = [])

Defines a client-side script.

Parameters

mixed $content
array $attributes

Return Value

string

static string section(mixed $content = '', array $attributes = [])

Defines a section in a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string select(mixed $content = '', array $attributes = [])

Defines a drop-down list.

Parameters

mixed $content
array $attributes

Return Value

string

static string small(mixed $content = '', array $attributes = [])

Defines smaller text.

Parameters

mixed $content
array $attributes

Return Value

string

static string source(array $attributes = [])

Defines multiple media resources for media elements (<video> and <audio>).

Parameters

array $attributes

Return Value

string

static string span(mixed $content = '', array $attributes = [])

Defines a section in a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string strike(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use <del> or <s> instead. Defines strikethrough text.

Parameters

mixed $content
array $attributes

Return Value

string

protected string stringifyAttributes(array $attributes)

Returns an HTML attributes string from an associative array of attributes.

Parameters

array $attributes

Return Value

string

static string strong(mixed $content = '', array $attributes = [])

Defines important text.

Parameters

mixed $content
array $attributes

Return Value

string

static string style(mixed $content = '', array $attributes = [])

Defines style information for a document.

Parameters

mixed $content
array $attributes

Return Value

string

static string sub(mixed $content = '', array $attributes = [])

Defines subscripted text.

Parameters

mixed $content
array $attributes

Return Value

string

static string summary(mixed $content = '', array $attributes = [])

Defines a visible heading for a <details> element.

Parameters

mixed $content
array $attributes

Return Value

string

static string sup(mixed $content = '', array $attributes = [])

Defines superscripted text.

Parameters

mixed $content
array $attributes

Return Value

string

static string svg(mixed $content = '', array $attributes = [])

Defines a container for SVG graphics.

Parameters

mixed $content
array $attributes

Return Value

string

static string table(mixed $content = '', array $attributes = [])

Defines a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string tbody(mixed $content = '', array $attributes = [])

Groups the body content in a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string td(mixed $content = '', array $attributes = [])

Defines a cell in a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string template(mixed $content = '', array $attributes = [])

Defines a container for content that should be hidden when the page loads.

Parameters

mixed $content
array $attributes

Return Value

string

static string textarea(mixed $content = '', array $attributes = [])

Defines a multiline input control (text area).

Parameters

mixed $content
array $attributes

Return Value

string

static string tfoot(mixed $content = '', array $attributes = [])

Groups the footer content in a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string th(mixed $content = '', array $attributes = [])

Defines a header cell in a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string thead(mixed $content = '', array $attributes = [])

Groups the header content in a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string time(mixed $content = '', array $attributes = [])

Defines a specific time (or datetime).

Parameters

mixed $content
array $attributes

Return Value

string

static string title(mixed $content = '', array $attributes = [])

Defines a title for the document.

Parameters

mixed $content
array $attributes

Return Value

string

static string tr(mixed $content = '', array $attributes = [])

Defines a row in a table.

Parameters

mixed $content
array $attributes

Return Value

string

static string track(array $attributes = [])

Defines text tracks for media elements (<video> and <audio>).

Parameters

array $attributes

Return Value

string

static string tt(mixed $content = '', array $attributes = [])

Not supported in HTML5. Use CSS instead. Defines teletype text.

Parameters

mixed $content
array $attributes

Return Value

string

static string u(mixed $content = '', array $attributes = [])

Defines some text that is unarticulated and styled differently from normal text.

Parameters

mixed $content
array $attributes

Return Value

string

static string ul(mixed $content = '', array $attributes = [])

Defines an unordered list.

Parameters

mixed $content
array $attributes

Return Value

string

static void validate(string $html)

Asserts that the passed HTML is valid.

Parameters

string $html

Return Value

void

Exceptions

Exception

static string var(mixed $content = '', array $attributes = [])

Defines a variable.

Parameters

mixed $content
array $attributes

Return Value

string

static string video(mixed $content = '', array $attributes = [])

Defines embedded video content.

Parameters

mixed $content
array $attributes

Return Value

string

static string wbr(array $attributes = [])

Defines a possible line-break.

Parameters

array $attributes

Return Value

string

HTML write(string $content)

Writes content to the HTML buffer.

Parameters

string $content

The content to write. Note that the content will be indented if indentation is turned on (multiples of 4 spaces depending on the current stack).

Return Value

HTML