Html
class Html implements ArrayAccess, Countable, IteratorAggregate, HtmlStringable
Generates HTML elements with automatic attribute escaping.
Properties
| array<string,mixed> | $attrs | ||
| static array<string,int> | $emptyElements | ||
| protected array<int,self|string> | $children | ||
| ?string | $accept | ||
| ?string | $accesskey | ||
| ?string | $action | ||
| ?string | $align | ||
| ?string | $allow | ||
| ?string | $alt | ||
| ?bool | $async | ||
| ?string | $autocapitalize | ||
| ?string | $autocomplete | ||
| ?bool | $autofocus | ||
| ?bool | $autoplay | ||
| ?string | $charset | ||
| ?bool | $checked | ||
| ?string | $cite | ||
| ?string | $class | ||
| ?int | $cols | ||
| ?int | $colspan | ||
| ?string | $content | ||
| ?bool | $contenteditable | ||
| ?bool | $controls | ||
| ?string | $coords | ||
| ?string | $crossorigin | ||
| ?string | $data | ||
| ?string | $datetime | ||
| ?string | $decoding | ||
| ?bool | $default | ||
| ?bool | $defer | ||
| ?string | $dir | ||
| ?string | $dirname | ||
| ?bool | $disabled | ||
| ?bool | $download | ||
| ?string | $draggable | ||
| ?string | $dropzone | ||
| ?string | $enctype | ||
| ?string | $for | ||
| ?string | $form | ||
| ?string | $formaction | ||
| ?string | $formenctype | ||
| ?string | $formmethod | ||
| ?bool | $formnovalidate | ||
| ?string | $formtarget | ||
| ?string | $headers | ||
| ?int | $height | ||
| $hidden | |||
| ?float | $high | ||
| ?string | $href | ||
| ?string | $hreflang | ||
| ?string | $id | ||
| ?string | $integrity | ||
| ?string | $inputmode | ||
| ?bool | $ismap | ||
| ?string | $itemprop | ||
| ?string | $kind | ||
| ?string | $label | ||
| ?string | $lang | ||
| ?string | $list | ||
| ?bool | $loop | ||
| ?float | $low | ||
| ?float | $max | ||
| ?int | $maxlength | ||
| ?int | $minlength | ||
| ?string | $media | ||
| ?string | $method | ||
| ?float | $min | ||
| ?bool | $multiple | ||
| ?bool | $muted | ||
| ?string | $name | ||
| ?bool | $novalidate | ||
| ?bool | $open | ||
| ?float | $optimum | ||
| ?string | $pattern | ||
| ?string | $ping | ||
| ?string | $placeholder | ||
| ?string | $poster | ||
| ?string | $preload | ||
| ?string | $radiogroup | ||
| ?bool | $readonly | ||
| ?string | $rel | ||
| ?bool | $required | ||
| ?bool | $reversed | ||
| ?int | $rows | ||
| ?int | $rowspan | ||
| ?string | $sandbox | ||
| ?string | $scope | ||
| ?bool | $selected | ||
| ?string | $shape | ||
| ?int | $size | ||
| ?string | $sizes | ||
| ?string | $slot | ||
| ?int | $span | ||
| ?string | $spellcheck | ||
| ?string | $src | ||
| ?string | $srcdoc | ||
| ?string | $srclang | ||
| ?string | $srcset | ||
| ?int | $start | ||
| ?float | $step | ||
| ?string | $style | ||
| ?int | $tabindex | ||
| ?string | $target | ||
| ?string | $title | ||
| ?string | $translate | ||
| ?string | $type | ||
| ?string | $usemap | ||
| ?string | $value | ||
| ?int | $width | ||
| ?string | $wrap |
Methods
Constructs new HTML element.
Converts to HTML.
Converts to plain text.
Converts given HTML code to plain text.
Returns element's name.
Checks whether the element is a void (self-closing) element.
Sets multiple attributes.
Appends value to element's attribute.
Sets element's attribute.
Returns element's attribute.
Unsets element's attribute.
Unsets element's attributes.
Sets element's attribute via property assignment.
Returns element's attribute via property access.
Checks if element's attribute is set.
Unsets element's attribute via property unset.
Sets or returns element's attribute via method call.
Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.
Returns element's HTML content.
Returns element's textual content.
Inserts child node.
Returns child node (\ArrayAccess implementation).
Exists child node? (\ArrayAccess implementation).
Removes child node (\ArrayAccess implementation).
Returns children count.
Removes all children.
Iterates over elements.
Returns all children.
Renders element's start tag, content and end tag. Pass indent level to enable pretty-printing.
Returns string in HTML format.
Returns element's start tag.
Returns element's end tag.
Returns element's attributes.
Clones all children too.
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
No description
Details
at line 260
static Html
el(string|null $name = null, array|string|null $attrs = null)
Constructs new HTML element.
at line 286
static Html
fromHtml(string $html)
Returns an object representing HTML text.
at line 295
static Html
fromText(string $text)
Returns an object representing plain text.
at line 304
final string
toHtml()
Converts to HTML.
at line 313
final string
toText()
Converts to plain text.
at line 322
static string
htmlToText(string $html)
Converts given HTML code to plain text.
at line 331
final Html
setName(string $name, bool|null $isEmpty = null)
Changes element's name.
at line 342
final string
getName()
Returns element's name.
at line 351
final bool
isEmpty()
Checks whether the element is a void (self-closing) element.
at line 361
Html
addAttributes(array $attrs)
Sets multiple attributes.
at line 371
Html
appendAttribute(string $name, mixed $value, mixed $option = true)
Appends value to element's attribute.
at line 394
Html
setAttribute(string $name, mixed $value)
Sets element's attribute.
at line 404
mixed
getAttribute(string $name)
Returns element's attribute.
at line 413
Html
removeAttribute(string $name)
Unsets element's attribute.
at line 424
Html
removeAttributes(array $attributes)
Unsets element's attributes.
at line 437
final void
__set(string $name, mixed $value)
Sets element's attribute via property assignment.
at line 446
final mixed
__get(string $name)
Returns element's attribute via property access.
at line 455
final bool
__isset(string $name)
Checks if element's attribute is set.
at line 464
final void
__unset(string $name)
Unsets element's attribute via property unset.
at line 474
final mixed
__call(string $m, array $args)
Sets or returns element's attribute via method call.
at line 505
final Html
href(string $path, array $query = [])
Special setter for element's attribute.
at line 522
Html
data(string $name, mixed $value = null)
Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.
at line 539
final Html
setHtml(mixed $html)
Sets element's HTML content.
at line 549
final string
getHtml()
Returns element's HTML content.
at line 558
final Html
setText(mixed $text)
Sets element's textual content.
at line 572
final string
getText()
Returns element's textual content.
at line 581
final Html
addHtml(HtmlStringable|string $child)
Adds new element's child.
at line 590
Html
addText(Stringable|string|int|null $text)
Appends plain-text string to element content.
at line 604
final Html
create(string $name, array|string|null $attrs = null)
Creates and adds a new Html child.
at line 614
Html
insert(int|null $index, HtmlStringable|string $child, bool $replace = false)
Inserts child node.
at line 633
final void
offsetSet(?int $index, Html|string $child)
Inserts (replaces) child node (\ArrayAccess implementation).
at line 643
final self|string
offsetGet(int $index)
Returns child node (\ArrayAccess implementation).
at line 653
final bool
offsetExists(int $index)
Exists child node? (\ArrayAccess implementation).
at line 663
void
offsetUnset(int $index)
Removes child node (\ArrayAccess implementation).
at line 674
final int
count()
Returns children count.
at line 683
void
removeChildren()
Removes all children.
at line 693
final ArrayIterator
getIterator()
Iterates over elements.
at line 703
final array
getChildren()
Returns all children.
at line 712
final string
render(int|null $indent = null)
Renders element's start tag, content and end tag. Pass indent level to enable pretty-printing.
at line 742
final string
__toString()
Returns string in HTML format.
at line 751
final string
startTag()
Returns element's start tag.
at line 762
final string
endTag()
Returns element's end tag.
at line 772
final string
attributes()
| internal |
Returns element's attributes.
at line 832
__clone()
Clones all children too.
at line 235
self
accept(?string $val)
No description
at line 235
self
accesskey(?string $val, bool $state = null)
No description
at line 235
self
action(?string $val)
No description
at line 235
self
align(?string $val)
No description
at line 235
self
allow(?string $val, bool $state = null)
No description
at line 235
self
alt(?string $val)
No description
at line 235
self
async(?bool $val)
No description
at line 235
self
autocapitalize(?string $val)
No description
at line 235
self
autocomplete(?string $val)
No description
at line 235
self
autofocus(?bool $val)
No description
at line 235
self
autoplay(?bool $val)
No description
at line 235
self
charset(?string $val)
No description
at line 235
self
checked(?bool $val)
No description
at line 235
self
cite(?string $val)
No description
at line 235
self
class(?string $val, bool $state = null)
No description
at line 235
self
cols(?int $val)
No description
at line 235
self
colspan(?int $val)
No description
at line 235
self
content(?string $val)
No description
at line 235
self
contenteditable(?bool $val)
No description
at line 235
self
controls(?bool $val)
No description
at line 235
self
coords(?string $val)
No description
at line 235
self
crossorigin(?string $val)
No description
at line 235
self
datetime(?string $val)
No description
at line 235
self
decoding(?string $val)
No description
at line 235
self
default(?bool $val)
No description
at line 235
self
defer(?bool $val)
No description
at line 235
self
dir(?string $val)
No description
at line 235
self
dirname(?string $val)
No description
at line 235
self
disabled(?bool $val)
No description
at line 235
self
download(?bool $val)
No description
at line 235
self
draggable(?string $val)
No description
at line 235
self
dropzone(?string $val)
No description
at line 235
self
enctype(?string $val)
No description
at line 235
self
for(?string $val)
No description
at line 235
self
form(?string $val)
No description
at line 235
self
formaction(?string $val)
No description
at line 235
self
formenctype(?string $val)
No description
at line 235
self
formmethod(?string $val)
No description
at line 235
self
formnovalidate(?bool $val)
No description
at line 235
self
formtarget(?string $val)
No description
at line 235
self
headers(?string $val, bool $state = null)
No description
at line 235
self
height(?int $val)
No description
at line 235
self
hidden(?bool $val)
No description
at line 235
self
high(?float $val)
No description
at line 235
self
hreflang(?string $val)
No description
at line 235
self
id(?string $val)
No description
at line 235
self
integrity(?string $val)
No description
at line 235
self
inputmode(?string $val)
No description
at line 235
self
ismap(?bool $val)
No description
at line 235
self
itemprop(?string $val)
No description
at line 235
self
kind(?string $val)
No description
at line 235
self
label(?string $val)
No description
at line 235
self
lang(?string $val)
No description
at line 235
self
list(?string $val)
No description
at line 235
self
loop(?bool $val)
No description
at line 235
self
low(?float $val)
No description
at line 235
self
max(?float $val)
No description
at line 235
self
maxlength(?int $val)
No description
at line 235
self
minlength(?int $val)
No description
at line 235
self
media(?string $val)
No description
at line 235
self
method(?string $val)
No description
at line 235
self
min(?float $val)
No description
at line 235
self
multiple(?bool $val)
No description
at line 235
self
muted(?bool $val)
No description
at line 235
self
name(?string $val)
No description
at line 235
self
novalidate(?bool $val)
No description
at line 235
self
open(?bool $val)
No description
at line 235
self
optimum(?float $val)
No description
at line 235
self
pattern(?string $val)
No description
at line 235
self
ping(?string $val, bool $state = null)
No description
at line 235
self
placeholder(?string $val)
No description
at line 235
self
poster(?string $val)
No description
at line 235
self
preload(?string $val)
No description
at line 235
self
radiogroup(?string $val)
No description
at line 235
self
readonly(?bool $val)
No description
at line 235
self
rel(?string $val)
No description
at line 235
self
required(?bool $val)
No description
at line 235
self
reversed(?bool $val)
No description
at line 235
self
rows(?int $val)
No description
at line 235
self
rowspan(?int $val)
No description
at line 235
self
sandbox(?string $val, bool $state = null)
No description
at line 235
self
scope(?string $val)
No description
at line 235
self
selected(?bool $val)
No description
at line 235
self
shape(?string $val)
No description
at line 235
self
size(?int $val)
No description
at line 235
self
sizes(?string $val)
No description
at line 235
self
slot(?string $val)
No description
at line 235
self
span(?int $val)
No description
at line 235
self
spellcheck(?string $val)
No description
at line 235
self
src(?string $val)
No description
at line 235
self
srcdoc(?string $val)
No description
at line 235
self
srclang(?string $val)
No description
at line 235
self
srcset(?string $val)
No description
at line 235
self
start(?int $val)
No description
at line 235
self
step(?float $val)
No description
at line 235
self
style(?string $property, string $val = null)
No description
at line 235
self
tabindex(?int $val)
No description
at line 235
self
target(?string $val)
No description
at line 235
self
title(?string $val)
No description
at line 235
self
translate(?string $val)
No description
at line 235
self
type(?string $val)
No description
at line 235
self
usemap(?string $val)
No description
at line 235
self
value(?string $val)
No description
at line 235
self
width(?int $val)
No description
at line 235
self
wrap(?string $val)
No description