class Html implements ArrayAccess, Countable, IteratorAggregate, HtmlStringable

HTML helper.

Traits

Strict class for better experience.

Properties

array $attrs
static bool $xhtml
static array $emptyElements
protected array $children
string|null $accept
string|null $accesskey
string|null $action
string|null $align
string|null $allow
string|null $alt
bool|null $async
string|null $autocapitalize
string|null $autocomplete
bool|null $autofocus
bool|null $autoplay
string|null $charset
bool|null $checked
string|null $cite
string|null $class
int|null $cols
int|null $colspan
string|null $content
bool|null $contenteditable
bool|null $controls
string|null $coords
string|null $crossorigin
string|null $data
string|null $datetime
string|null $decoding
bool|null $default
bool|null $defer
string|null $dir
string|null $dirname
bool|null $disabled
bool|null $download
string|null $draggable
string|null $dropzone
string|null $enctype
string|null $for
string|null $form
string|null $formaction
string|null $formenctype
string|null $formmethod
bool|null $formnovalidate
string|null $formtarget
string|null $headers
int|null $height
bool|null $hidden
float|null $high
string|null $href
string|null $hreflang
string|null $id
string|null $integrity
string|null $inputmode
bool|null $ismap
string|null $itemprop
string|null $kind
string|null $label
string|null $lang
string|null $list
bool|null $loop
float|null $low
float|null $max
int|null $maxlength
int|null $minlength
string|null $media
string|null $method
float|null $min
bool|null $multiple
bool|null $muted
string|null $name
bool|null $novalidate
bool|null $open
float|null $optimum
string|null $pattern
string|null $ping
string|null $placeholder
string|null $poster
string|null $preload
string|null $radiogroup
bool|null $readonly
string|null $rel
bool|null $required
bool|null $reversed
int|null $rows
int|null $rowspan
string|null $sandbox
string|null $scope
bool|null $selected
string|null $shape
int|null $size
string|null $sizes
string|null $slot
int|null $span
string|null $spellcheck
string|null $src
string|null $srcdoc
string|null $srclang
string|null $srcset
int|null $start
float|null $step
string|null $style
int|null $tabindex
string|null $target
string|null $title
string|null $translate
string|null $type
string|null $usemap
string|null $value
int|null $width
string|null $wrap

Methods

static Html
el(string $name = null, $attrs = null)

Constructs new HTML element.

static Html
fromHtml(string $html)

Returns an object representing HTML text.

static Html
fromText(string $text)

Returns an object representing plain text.

string
toHtml()

Converts to HTML.

string
toText()

Converts to plain text.

static string
htmlToText(string $html)

Converts given HTML code to plain text.

setName(string $name, bool $isEmpty = null)

Changes element's name.

string
getName()

Returns element's name.

bool
isEmpty()

Is element empty?

addAttributes(array $attrs)

Sets multiple attributes.

appendAttribute(string $name, $value, $option = true)

Appends value to element's attribute.

setAttribute(string $name, $value)

Sets element's attribute.

mixed
getAttribute(string $name)

Returns element's attribute.

removeAttribute(string $name)

Unsets element's attribute.

removeAttributes(array $attributes)

Unsets element's attributes.

void
__set(string $name, $value)

Overloaded setter for element's attribute.

mixed
__get(string $name)

Overloaded getter for element's attribute.

bool
__isset(string $name)

Overloaded tester for element's attribute.

void
__unset(string $name)

Overloaded unsetter for element's attribute.

mixed
__call(string $m, array $args)

Overloaded setter for element's attribute.

href(string $path, array $query = null)

Special setter for element's attribute.

data(string $name, $value = null)

Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.

setHtml(HtmlStringable|string $html)

Sets element's HTML content.

string
getHtml()

Returns element's HTML content.

setText(HtmlStringable|string|int|float $text)

Sets element's textual content.

string
getText()

Returns element's textual content.

addHtml(HtmlStringable|string $child)

Adds new element's child.

addText(HtmlStringable|string|int|float $text)

Appends plain-text string to element content.

create(string $name, $attrs = null)

Creates and adds a new Html child.

insert(int|null $index, $child, bool $replace = false)

Inserts child node.

void
offsetSet(int|null $index, Html|string $child)

Inserts (replaces) child node (\ArrayAccess implementation).

Html|string
offsetGet(int $index)

Returns child node (\ArrayAccess implementation).

bool
offsetExists(int $index)

Exists child node? (\ArrayAccess implementation).

void
offsetUnset(int $index)

Removes child node (\ArrayAccess implementation).

int
count()

Returns children count.

void
removeChildren()

Removes all children.

getIterator()

Iterates over elements.

array
getChildren()

Returns all children.

string
render(int $indent = null)

Renders element's start tag, content and end tag.

string
__toString()

Returns string in HTML format

string
startTag()

Returns element's start tag.

string
endTag()

Returns element's end tag.

string
attributes()

Returns element's attributes.

__clone()

Clones all children too.

self
accept()

No description

self
accesskey(bool $state = null)

No description

self
action()

No description

self
align()

No description

self
allow(bool $state = null)

No description

self
alt()

No description

self
async()

No description

self
autocapitalize()

No description

self
autocomplete()

No description

self
autofocus()

No description

self
autoplay()

No description

self
charset()

No description

self
checked()

No description

self
cite()

No description

self
class(bool $state = null)

No description

self
cols()

No description

self
colspan()

No description

self
content()

No description

self
contenteditable()

No description

self
controls()

No description

self
coords()

No description

self
crossorigin()

No description

self
datetime()

No description

self
decoding()

No description

self
default()

No description

self
defer()

No description

self
dir()

No description

self
dirname()

No description

self
disabled()

No description

self
download()

No description

self
draggable()

No description

self
dropzone()

No description

self
enctype()

No description

self
for()

No description

self
form()

No description

self
formaction()

No description

self
formenctype()

No description

self
formmethod()

No description

self
formnovalidate()

No description

self
formtarget()

No description

self
headers(bool $state = null)

No description

self
height()

No description

self
hidden()

No description

self
high()

No description

self
hreflang()

No description

self
id()

No description

self
integrity()

No description

self
inputmode()

No description

self
ismap()

No description

self
itemprop()

No description

self
kind()

No description

self
label()

No description

self
lang()

No description

self
list()

No description

self
loop()

No description

self
low()

No description

self
max()

No description

self
maxlength()

No description

self
minlength()

No description

self
media()

No description

self
method()

No description

self
min()

No description

self
multiple()

No description

self
muted()

No description

self
name()

No description

self
novalidate()

No description

self
open()

No description

self
optimum()

No description

self
pattern()

No description

self
ping(bool $state = null)

No description

self
placeholder()

No description

self
poster()

No description

self
preload()

No description

self
radiogroup()

No description

self
readonly()

No description

self
rel()

No description

self
required()

No description

self
reversed()

No description

self
rows()

No description

self
rowspan()

No description

self
sandbox(bool $state = null)

No description

self
scope()

No description

self
selected()

No description

self
shape()

No description

self
size()

No description

self
sizes()

No description

self
slot()

No description

self
span()

No description

self
spellcheck()

No description

self
src()

No description

self
srcdoc()

No description

self
srclang()

No description

self
srcset()

No description

self
start()

No description

self
step()

No description

self
style(string $val = null)

No description

self
tabindex()

No description

self
target()

No description

self
title()

No description

self
translate()

No description

self
type()

No description

self
usemap()

No description

self
value()

No description

self
width()

No description

self
wrap()

No description

Details

at line 266
static Html el(string $name = null, $attrs = null)

Constructs new HTML element.

Parameters

string $name
$attrs

Return Value

Html

at line 292
static Html fromHtml(string $html)

Returns an object representing HTML text.

Parameters

string $html

Return Value

Html

at line 301
static Html fromText(string $text)

Returns an object representing plain text.

Parameters

string $text

Return Value

Html

at line 310
final string toHtml()

Converts to HTML.

Return Value

string

at line 319
final string toText()

Converts to plain text.

Return Value

string

at line 328
static string htmlToText(string $html)

Converts given HTML code to plain text.

Parameters

string $html

Return Value

string

at line 338
final Html setName(string $name, bool $isEmpty = null)

Changes element's name.

Parameters

string $name
bool $isEmpty

Return Value

Html

at line 349
final string getName()

Returns element's name.

Return Value

string

at line 358
final bool isEmpty()

Is element empty?

Return Value

bool

at line 368
Html addAttributes(array $attrs)

Sets multiple attributes.

Parameters

array $attrs

Return Value

Html

at line 381
Html appendAttribute(string $name, $value, $option = true)

Appends value to element's attribute.

Parameters

string $name
$value
$option

Return Value

Html

at line 405
Html setAttribute(string $name, $value)

Sets element's attribute.

Parameters

string $name
$value

Return Value

Html

at line 416
mixed getAttribute(string $name)

Returns element's attribute.

Parameters

string $name

Return Value

mixed

at line 426
Html removeAttribute(string $name)

Unsets element's attribute.

Parameters

string $name

Return Value

Html

at line 437
Html removeAttributes(array $attributes)

Unsets element's attributes.

Parameters

array $attributes

Return Value

Html

at line 450
final void __set(string $name, $value)

Overloaded setter for element's attribute.

Parameters

string $name
$value

Return Value

void

at line 460
final mixed __get(string $name)

Overloaded getter for element's attribute.

Parameters

string $name

Return Value

mixed

at line 469
final bool __isset(string $name)

Overloaded tester for element's attribute.

Parameters

string $name

Return Value

bool

at line 478
final void __unset(string $name)

Overloaded unsetter for element's attribute.

Parameters

string $name

Return Value

void

at line 488
final mixed __call(string $m, array $args)

Overloaded setter for element's attribute.

Parameters

string $m
array $args

Return Value

mixed

at line 519
final Html href(string $path, array $query = null)

Special setter for element's attribute.

Parameters

string $path
array $query

Return Value

Html

at line 537
Html data(string $name, $value = null)

Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.

Parameters

string $name
$value

Return Value

Html

at line 553
final Html setHtml(HtmlStringable|string $html)

Sets element's HTML content.

Parameters

HtmlStringable|string $html

Return Value

Html

at line 563
final string getHtml()

Returns element's HTML content.

Return Value

string

at line 574
final Html setText(HtmlStringable|string|int|float $text)

Sets element's textual content.

Parameters

HtmlStringable|string|int|float $text

Return Value

Html

at line 587
final string getText()

Returns element's textual content.

Return Value

string

at line 598
final Html addHtml(HtmlStringable|string $child)

Adds new element's child.

Parameters

HtmlStringable|string $child Html node or raw HTML string

Return Value

Html

at line 609
Html addText(HtmlStringable|string|int|float $text)

Appends plain-text string to element content.

Parameters

HtmlStringable|string|int|float $text

Return Value

Html

at line 623
final Html create(string $name, $attrs = null)

Creates and adds a new Html child.

Parameters

string $name
$attrs

Return Value

Html created element

at line 635
Html insert(int|null $index, $child, bool $replace = false)

Inserts child node.

Parameters

int|null $index
$child
bool $replace

Return Value

Html

at line 654
final void offsetSet(int|null $index, Html|string $child)

Inserts (replaces) child node (\ArrayAccess implementation).

Parameters

int|null $index position or null for appending
Html|string $child Html node or raw HTML string

Return Value

void

at line 665
final Html|string offsetGet(int $index)

Returns child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

Html|string

at line 675
final bool offsetExists(int $index)

Exists child node? (\ArrayAccess implementation).

Parameters

int $index

Return Value

bool

at line 685
void offsetUnset(int $index)

Removes child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

void

at line 696
final int count()

Returns children count.

Return Value

int

at line 705
void removeChildren()

Removes all children.

Return Value

void

at line 714
final ArrayIterator getIterator()

Iterates over elements.

Return Value

ArrayIterator

at line 723
final array getChildren()

Returns all children.

Return Value

array

at line 732
final string render(int $indent = null)

Renders element's start tag, content and end tag.

Parameters

int $indent

Return Value

string

at line 760
final string __toString()

Returns string in HTML format

Return Value

string

at line 777
final string startTag()

Returns element's start tag.

Return Value

string

at line 788
final string endTag()

Returns element's end tag.

Return Value

string

at line 798
final string attributes()

Returns element's attributes.

Return Value

string

at line 863
__clone()

Clones all children too.

at line 234
self accept()

Return Value

self

at line 234
self accesskey(bool $state = null)

Parameters

bool $state

Return Value

self

at line 234
self action()

Return Value

self

at line 234
self align()

Return Value

self

at line 234
self allow(bool $state = null)

Parameters

bool $state

Return Value

self

at line 234
self alt()

Return Value

self

at line 234
self async()

Return Value

self

at line 234
self autocapitalize()

Return Value

self

at line 234
self autocomplete()

Return Value

self

at line 234
self autofocus()

Return Value

self

at line 234
self autoplay()

Return Value

self

at line 234
self charset()

Return Value

self

at line 234
self checked()

Return Value

self

at line 234
self cite()

Return Value

self

at line 234
self class(bool $state = null)

Parameters

bool $state

Return Value

self

at line 234
self cols()

Return Value

self

at line 234
self colspan()

Return Value

self

at line 234
self content()

Return Value

self

at line 234
self contenteditable()

Return Value

self

at line 234
self controls()

Return Value

self

at line 234
self coords()

Return Value

self

at line 234
self crossorigin()

Return Value

self

at line 234
self datetime()

Return Value

self

at line 234
self decoding()

Return Value

self

at line 234
self default()

Return Value

self

at line 234
self defer()

Return Value

self

at line 234
self dir()

Return Value

self

at line 234
self dirname()

Return Value

self

at line 234
self disabled()

Return Value

self

at line 234
self download()

Return Value

self

at line 234
self draggable()

Return Value

self

at line 234
self dropzone()

Return Value

self

at line 234
self enctype()

Return Value

self

at line 234
self for()

Return Value

self

at line 234
self form()

Return Value

self

at line 234
self formaction()

Return Value

self

at line 234
self formenctype()

Return Value

self

at line 234
self formmethod()

Return Value

self

at line 234
self formnovalidate()

Return Value

self

at line 234
self formtarget()

Return Value

self

at line 234
self headers(bool $state = null)

Parameters

bool $state

Return Value

self

at line 234
self height()

Return Value

self

at line 234
self hidden()

Return Value

self

at line 234
self high()

Return Value

self

at line 234
self hreflang()

Return Value

self

at line 234
self id()

Return Value

self

at line 234
self integrity()

Return Value

self

at line 234
self inputmode()

Return Value

self

at line 234
self ismap()

Return Value

self

at line 234
self itemprop()

Return Value

self

at line 234
self kind()

Return Value

self

at line 234
self label()

Return Value

self

at line 234
self lang()

Return Value

self

at line 234
self list()

Return Value

self

at line 234
self loop()

Return Value

self

at line 234
self low()

Return Value

self

at line 234
self max()

Return Value

self

at line 234
self maxlength()

Return Value

self

at line 234
self minlength()

Return Value

self

at line 234
self media()

Return Value

self

at line 234
self method()

Return Value

self

at line 234
self min()

Return Value

self

at line 234
self multiple()

Return Value

self

at line 234
self muted()

Return Value

self

at line 234
self name()

Return Value

self

at line 234
self novalidate()

Return Value

self

at line 234
self open()

Return Value

self

at line 234
self optimum()

Return Value

self

at line 234
self pattern()

Return Value

self

at line 234
self ping(bool $state = null)

Parameters

bool $state

Return Value

self

at line 234
self placeholder()

Return Value

self

at line 234
self poster()

Return Value

self

at line 234
self preload()

Return Value

self

at line 234
self radiogroup()

Return Value

self

at line 234
self readonly()

Return Value

self

at line 234
self rel()

Return Value

self

at line 234
self required()

Return Value

self

at line 234
self reversed()

Return Value

self

at line 234
self rows()

Return Value

self

at line 234
self rowspan()

Return Value

self

at line 234
self sandbox(bool $state = null)

Parameters

bool $state

Return Value

self

at line 234
self scope()

Return Value

self

at line 234
self selected()

Return Value

self

at line 234
self shape()

Return Value

self

at line 234
self size()

Return Value

self

at line 234
self sizes()

Return Value

self

at line 234
self slot()

Return Value

self

at line 234
self span()

Return Value

self

at line 234
self spellcheck()

Return Value

self

at line 234
self src()

Return Value

self

at line 234
self srcdoc()

Return Value

self

at line 234
self srclang()

Return Value

self

at line 234
self srcset()

Return Value

self

at line 234
self start()

Return Value

self

at line 234
self step()

Return Value

self

at line 234
self style(string $val = null)

Parameters

string $val

Return Value

self

at line 234
self tabindex()

Return Value

self

at line 234
self target()

Return Value

self

at line 234
self title()

Return Value

self

at line 234
self translate()

Return Value

self

at line 234
self type()

Return Value

self

at line 234
self usemap()

Return Value

self

at line 234
self value()

Return Value

self

at line 234
self width()

Return Value

self

at line 234
self wrap()

Return Value

self