class Html implements ArrayAccess, Countable, IteratorAggregate, HtmlStringable

HTML helper.

Properties

array<string,mixed> $attrs
static bool $xhtml
static array<string,int> $emptyElements
protected HtmlStringable|string> $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, array|string $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, mixed $value, mixed $option = true)

Appends value to element's attribute.

setAttribute(string $name, mixed $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, mixed $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, mixed $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, array|string $attrs = null)

Creates and adds a new Html child.

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

Inserts child node.

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

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

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(?string $val)

No description

self
accesskey(?string $val, bool $state = null)

No description

self
action(?string $val)

No description

self
align(?string $val)

No description

self
allow(?string $val, bool $state = null)

No description

self
alt(?string $val)

No description

self
async(?bool $val)

No description

self
autocapitalize(?string $val)

No description

self
autocomplete(?string $val)

No description

self
autofocus(?bool $val)

No description

self
autoplay(?bool $val)

No description

self
charset(?string $val)

No description

self
checked(?bool $val)

No description

self
cite(?string $val)

No description

self
class(?string $val, bool $state = null)

No description

self
cols(?int $val)

No description

self
colspan(?int $val)

No description

self
content(?string $val)

No description

self
contenteditable(?bool $val)

No description

self
controls(?bool $val)

No description

self
coords(?string $val)

No description

self
crossorigin(?string $val)

No description

self
datetime(?string $val)

No description

self
decoding(?string $val)

No description

self
default(?bool $val)

No description

self
defer(?bool $val)

No description

self
dir(?string $val)

No description

self
dirname(?string $val)

No description

self
disabled(?bool $val)

No description

self
download(?bool $val)

No description

self
draggable(?string $val)

No description

self
dropzone(?string $val)

No description

self
enctype(?string $val)

No description

self
for(?string $val)

No description

self
form(?string $val)

No description

self
formaction(?string $val)

No description

self
formenctype(?string $val)

No description

self
formmethod(?string $val)

No description

self
formnovalidate(?bool $val)

No description

self
formtarget(?string $val)

No description

self
headers(?string $val, bool $state = null)

No description

self
height(?int $val)

No description

self
hidden(?bool $val)

No description

self
high(?float $val)

No description

self
hreflang(?string $val)

No description

self
id(?string $val)

No description

self
integrity(?string $val)

No description

self
inputmode(?string $val)

No description

self
ismap(?bool $val)

No description

self
itemprop(?string $val)

No description

self
kind(?string $val)

No description

self
label(?string $val)

No description

self
lang(?string $val)

No description

self
list(?string $val)

No description

self
loop(?bool $val)

No description

self
low(?float $val)

No description

self
max(?float $val)

No description

self
maxlength(?int $val)

No description

self
minlength(?int $val)

No description

self
media(?string $val)

No description

self
method(?string $val)

No description

self
min(?float $val)

No description

self
multiple(?bool $val)

No description

self
muted(?bool $val)

No description

self
name(?string $val)

No description

self
novalidate(?bool $val)

No description

self
open(?bool $val)

No description

self
optimum(?float $val)

No description

self
pattern(?string $val)

No description

self
ping(?string $val, bool $state = null)

No description

self
placeholder(?string $val)

No description

self
poster(?string $val)

No description

self
preload(?string $val)

No description

self
radiogroup(?string $val)

No description

self
readonly(?bool $val)

No description

self
rel(?string $val)

No description

self
required(?bool $val)

No description

self
reversed(?bool $val)

No description

self
rows(?int $val)

No description

self
rowspan(?int $val)

No description

self
sandbox(?string $val, bool $state = null)

No description

self
scope(?string $val)

No description

self
selected(?bool $val)

No description

self
shape(?string $val)

No description

self
size(?int $val)

No description

self
sizes(?string $val)

No description

self
slot(?string $val)

No description

self
span(?int $val)

No description

self
spellcheck(?string $val)

No description

self
src(?string $val)

No description

self
srcdoc(?string $val)

No description

self
srclang(?string $val)

No description

self
srcset(?string $val)

No description

self
start(?int $val)

No description

self
step(?float $val)

No description

self
style(?string $property, string $val = null)

No description

self
tabindex(?int $val)

No description

self
target(?string $val)

No description

self
title(?string $val)

No description

self
translate(?string $val)

No description

self
type(?string $val)

No description

self
usemap(?string $val)

No description

self
value(?string $val)

No description

self
width(?int $val)

No description

self
wrap(?string $val)

No description

Details

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

Constructs new HTML element.

Parameters

string $name
array|string $attrs

element's attributes or plain text content

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, mixed $value, mixed $option = true)

Appends value to element's attribute.

Parameters

string $name
mixed $value
mixed $option

Return Value

Html

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

Sets element's attribute.

Parameters

string $name
mixed $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, mixed $value)

Overloaded setter for element's attribute.

Parameters

string $name
mixed $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, mixed $value = null)

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

Parameters

string $name
mixed $value

Return Value

Html

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

Sets element's HTML content.

Parameters

HtmlStringable|string $html

Return Value

Html

at line 565
final string getHtml()

Returns element's HTML content.

Return Value

string

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

Sets element's textual content.

Parameters

HtmlStringable|string|int|float $text

Return Value

Html

at line 589
final string getText()

Returns element's textual content.

Return Value

string

at line 600
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 611
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 625
final Html create(string $name, array|string $attrs = null)

Creates and adds a new Html child.

Parameters

string $name
array|string $attrs

element's attributes or raw HTML string

Return Value

Html

created element

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

Inserts child node.

Parameters

int|null $index
HtmlStringable|string $child

Html node or raw HTML string

bool $replace

Return Value

Html

at line 656
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 667
final HtmlStringable|string offsetGet(int $index)

Returns child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

HtmlStringable|string

at line 678
final bool offsetExists(int $index)

Exists child node? (\ArrayAccess implementation).

Parameters

int $index

Return Value

bool

at line 688
void offsetUnset(int $index)

Removes child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

void

at line 699
final int count()

Returns children count.

Return Value

int

at line 708
void removeChildren()

Removes all children.

Return Value

void

at line 718
final ArrayIterator getIterator()

Iterates over elements.

Return Value

ArrayIterator

at line 727
final array getChildren()

Returns all children.

Return Value

array

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

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

Parameters

int $indent

Return Value

string

at line 764
final string __toString()

Returns string in HTML format

Return Value

string

at line 781
final string startTag()

Returns element's start tag.

Return Value

string

at line 792
final string endTag()

Returns element's end tag.

Return Value

string

at line 802
final string attributes()

internal  
 

Returns element's attributes.

Return Value

string

at line 869
__clone()

Clones all children too.

at line 234
self accept(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self accesskey(?string $val, bool $state = null)

No description

Parameters

?string $val
bool $state

Return Value

self

at line 234
self action(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self align(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self allow(?string $val, bool $state = null)

No description

Parameters

?string $val
bool $state

Return Value

self

at line 234
self alt(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self async(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self autocapitalize(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self autocomplete(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self autofocus(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self autoplay(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self charset(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self checked(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self cite(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self class(?string $val, bool $state = null)

No description

Parameters

?string $val
bool $state

Return Value

self

at line 234
self cols(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self colspan(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self content(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self contenteditable(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self controls(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self coords(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self crossorigin(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self datetime(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self decoding(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self default(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self defer(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self dir(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self dirname(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self disabled(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self download(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self draggable(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self dropzone(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self enctype(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self for(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self form(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self formaction(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self formenctype(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self formmethod(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self formnovalidate(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self formtarget(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self headers(?string $val, bool $state = null)

No description

Parameters

?string $val
bool $state

Return Value

self

at line 234
self height(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self hidden(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self high(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 234
self hreflang(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self id(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self integrity(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self inputmode(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self ismap(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self itemprop(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self kind(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self label(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self lang(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self list(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self loop(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self low(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 234
self max(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 234
self maxlength(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self minlength(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self media(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self method(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self min(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 234
self multiple(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self muted(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self name(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self novalidate(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self open(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self optimum(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 234
self pattern(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self ping(?string $val, bool $state = null)

No description

Parameters

?string $val
bool $state

Return Value

self

at line 234
self placeholder(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self poster(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self preload(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self radiogroup(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self readonly(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self rel(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self required(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self reversed(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self rows(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self rowspan(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self sandbox(?string $val, bool $state = null)

No description

Parameters

?string $val
bool $state

Return Value

self

at line 234
self scope(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self selected(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 234
self shape(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self size(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self sizes(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self slot(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self span(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self spellcheck(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self src(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self srcdoc(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self srclang(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self srcset(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self start(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self step(?float $val)

No description

Parameters

?float $val

Return Value

self

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

No description

Parameters

?string $property
string $val

Return Value

self

at line 234
self tabindex(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self target(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self title(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self translate(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self type(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self usemap(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self value(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 234
self width(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 234
self wrap(?string $val)

No description

Parameters

?string $val

Return Value

self

Traits

Strict class for better experience.