class Html implements ArrayAccess, Countable, IteratorAggregate, IHtmlString

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(IHtmlString|string $html)

Sets element's HTML content.

string
getHtml()

Returns element's HTML content.

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

Sets element's textual content.

string
getText()

Returns element's textual content.

addHtml(IHtmlString|string $child)

Adds new element's child.

addText(IHtmlString|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, IHtmlString|string $child, bool $replace = false)

Inserts child node.

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

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

HtmlStringable|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(?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 265
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 291
static Html fromHtml(string $html)

Returns an object representing HTML text.

Parameters

string $html

Return Value

Html

at line 300
static Html fromText(string $text)

Returns an object representing plain text.

Parameters

string $text

Return Value

Html

at line 309
final string toHtml()

Converts to HTML.

Return Value

string

at line 318
final string toText()

Converts to plain text.

Return Value

string

at line 327
static string htmlToText(string $html)

Converts given HTML code to plain text.

Parameters

string $html

Return Value

string

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

Changes element's name.

Parameters

string $name
bool $isEmpty

Return Value

Html

at line 348
final string getName()

Returns element's name.

Return Value

string

at line 357
final bool isEmpty()

Is element empty?

Return Value

bool

at line 367
Html addAttributes(array $attrs)

Sets multiple attributes.

Parameters

array $attrs

Return Value

Html

at line 380
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 404
Html setAttribute(string $name, mixed $value)

Sets element's attribute.

Parameters

string $name
mixed $value

Return Value

Html

at line 415
mixed getAttribute(string $name)

Returns element's attribute.

Parameters

string $name

Return Value

mixed

at line 425
Html removeAttribute(string $name)

Unsets element's attribute.

Parameters

string $name

Return Value

Html

at line 436
Html removeAttributes(array $attributes)

Unsets element's attributes.

Parameters

array $attributes

Return Value

Html

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

Overloaded setter for element's attribute.

Parameters

string $name
mixed $value

Return Value

void

at line 459
final mixed __get(string $name)

Overloaded getter for element's attribute.

Parameters

string $name

Return Value

mixed

at line 468
final bool __isset(string $name)

Overloaded tester for element's attribute.

Parameters

string $name

Return Value

bool

at line 477
final void __unset(string $name)

Overloaded unsetter for element's attribute.

Parameters

string $name

Return Value

void

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

Overloaded setter for element's attribute.

Parameters

string $m
array $args

Return Value

mixed

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

Special setter for element's attribute.

Parameters

string $path
array $query

Return Value

Html

at line 536
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 554
final Html setHtml(IHtmlString|string $html)

Sets element's HTML content.

Parameters

IHtmlString|string $html

Return Value

Html

at line 564
final string getHtml()

Returns element's HTML content.

Return Value

string

at line 575
final Html setText(IHtmlString|string|int|float $text)

Sets element's textual content.

Parameters

IHtmlString|string|int|float $text

Return Value

Html

at line 588
final string getText()

Returns element's textual content.

Return Value

string

at line 599
final Html addHtml(IHtmlString|string $child)

Adds new element's child.

Parameters

IHtmlString|string $child

Html node or raw HTML string

Return Value

Html

at line 610
Html addText(IHtmlString|string|int|float $text)

Appends plain-text string to element content.

Parameters

IHtmlString|string|int|float $text

Return Value

Html

at line 624
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 636
Html insert(int|null $index, IHtmlString|string $child, bool $replace = false)

Inserts child node.

Parameters

int|null $index
IHtmlString|string $child

Html node or raw HTML string

bool $replace

Return Value

Html

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

Returns child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

HtmlStringable|string

at line 676
final bool offsetExists(int $index)

Exists child node? (\ArrayAccess implementation).

Parameters

int $index

Return Value

bool

at line 686
void offsetUnset(int $index)

Removes child node (\ArrayAccess implementation).

Parameters

int $index

Return Value

void

at line 697
final int count()

Returns children count.

Return Value

int

at line 706
void removeChildren()

Removes all children.

Return Value

void

at line 716
final ArrayIterator getIterator()

Iterates over elements.

Return Value

ArrayIterator

at line 725
final array getChildren()

Returns all children.

Return Value

array

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

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

Parameters

int $indent

Return Value

string

at line 762
final string __toString()

Returns string in HTML format

Return Value

string

at line 779
final string startTag()

Returns element's start tag.

Return Value

string

at line 790
final string endTag()

Returns element's end tag.

Return Value

string

at line 800
final string attributes()

internal  
 

Returns element's attributes.

Return Value

string

at line 867
__clone()

Clones all children too.

at line 233
self accept(?string $val)

No description

Parameters

?string $val

Return Value

self

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

No description

Parameters

?string $val
bool $state

Return Value

self

at line 233
self action(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self align(?string $val)

No description

Parameters

?string $val

Return Value

self

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

No description

Parameters

?string $val
bool $state

Return Value

self

at line 233
self alt(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self async(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self autocapitalize(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self autocomplete(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self autofocus(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self autoplay(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self charset(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self checked(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self cite(?string $val)

No description

Parameters

?string $val

Return Value

self

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

No description

Parameters

?string $val
bool $state

Return Value

self

at line 233
self cols(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self colspan(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self content(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self contenteditable(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self controls(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self coords(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self crossorigin(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self datetime(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self decoding(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self default(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self defer(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self dir(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self dirname(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self disabled(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self download(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self draggable(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self dropzone(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self enctype(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self for(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self form(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self formaction(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self formenctype(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self formmethod(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self formnovalidate(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self formtarget(?string $val)

No description

Parameters

?string $val

Return Value

self

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

No description

Parameters

?string $val
bool $state

Return Value

self

at line 233
self height(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self hidden(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self high(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 233
self hreflang(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self id(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self integrity(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self inputmode(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self ismap(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self itemprop(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self kind(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self label(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self lang(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self list(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self loop(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self low(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 233
self max(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 233
self maxlength(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self minlength(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self media(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self method(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self min(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 233
self multiple(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self muted(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self name(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self novalidate(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self open(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self optimum(?float $val)

No description

Parameters

?float $val

Return Value

self

at line 233
self pattern(?string $val)

No description

Parameters

?string $val

Return Value

self

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

No description

Parameters

?string $val
bool $state

Return Value

self

at line 233
self placeholder(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self poster(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self preload(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self radiogroup(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self readonly(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self rel(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self required(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self reversed(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self rows(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self rowspan(?int $val)

No description

Parameters

?int $val

Return Value

self

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

No description

Parameters

?string $val
bool $state

Return Value

self

at line 233
self scope(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self selected(?bool $val)

No description

Parameters

?bool $val

Return Value

self

at line 233
self shape(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self size(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self sizes(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self slot(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self span(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self spellcheck(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self src(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self srcdoc(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self srclang(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self srcset(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self start(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self step(?float $val)

No description

Parameters

?float $val

Return Value

self

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

No description

Parameters

?string $property
string $val

Return Value

self

at line 233
self tabindex(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self target(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self title(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self translate(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self type(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self usemap(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self value(?string $val)

No description

Parameters

?string $val

Return Value

self

at line 233
self width(?int $val)

No description

Parameters

?int $val

Return Value

self

at line 233
self wrap(?string $val)

No description

Parameters

?string $val

Return Value

self

Traits

Strict class for better experience.