API / Minn / Html

Html final class

Minn\Html · public/minn/src/Minn/Html.php · 109 lines

HTML, the front door for escaping and cutting markup: plain static calls, one import away (use Minn\Html;), the way Minn\Http and Minn\Json are. Escaping at output boundaries goes through here.

Uses 2

Constants and properties

constSPLIT = '/(<(?:!--.*?(?:-->|$)|!\\[CDATA\\[.*?(?:\\]\\]>|$)|[^>]*>?))/s'

Markup's pieces of HTML: comments and CDATA whole (to the end when unclosed), else from "<" to the next ">".

Public

staticsplit(string $html): array#

Markup cut into text and HTML pieces, the HTML ones at the odd positions (wp_html_split): a comment or CDATA section is one piece whatever it holds, and a "<" in text starts a piece that runs to the next ">".

@return list<string>
staticesc(?string $value): string#

Text escaped for HTML.

staticattr(?string $value): string#

Text escaped for an attribute value.

staticaddClasses(string $html, array $classes, ?string $onClass = NULL): string#

Appends classes to the first element in a fragment (or to the first element already carrying $onClass), adding a class attribute when the element has none. Existing classes keep their order.

$classeslist<string>
staticstripAllTags(string $text, bool $collapseWhitespace = false): string#

Drops script and style elements with their contents, then every other tag; whitespace runs optionally collapse to one space.

statictextField(string $text, bool $keepNewlines, Closure $validUtf8, Closure $encodeLessThan): string#

A single line of plain text from user input: tags stripped, control whitespace folded, percent escapes removed. The caller passes its own UTF-8 check and less-than encoder so its filters keep applying.

$validUtf8Closure(string): string@param Closure(string): string $encodeLessThan
staticscriptBody(string $markup): ?string#

The code inside markup that is exactly one bare script element once the surrounding whitespace is gone, or null for anything else: a tag with attributes, an empty element, a missing end. The tag names match in any case and the code is returned as written.