API / Minn\Support / Entities

Entities final class

Minn\Support\Entities · public/minn/src/Minn/Support/Entities.php · 82 lines

HTML special-character encoding with the reference's quote styles and its "do not double encode" rule: an ampersand that already starts a known named or numeric entity stays as it is.

Constants and properties

privateDECODE = array ( '&' => '&', '&' => '&', '&' => '&', '<' => '<', '<' => '<', '<' => '<', '>' => '>', '>' => '>', '>' => '>', )
privateDOUBLE_QUOTES = array ( '"' => '"', '"' => '"', '"' => '"', )
privateSINGLE_QUOTES = array ( ''' => '\'', ''' => '\'', ''' => '\'', '&apos;' => '\'', )

Public

staticspecialchars(string $text, string|int|false $quoteStyle, bool $doubleEncode, callable $knownEntity): string#

The reference's special-characters escaping, with its quote styles and double-encoding rule.

$quoteStyleint|string|falseENT_* flags, 'single', 'double', or false for none
$knownEntitycallable(string): boolwhether a named entity is in the allowed table
staticdecode(string $text, string|int $quoteStyle): string#

The reverse of specialchars: the five characters back, with the quote pairs the style asks for.

staticconvertInvalid(string $text): string#

Windows-1252 numeric references rewritten as the Unicode references they meant.

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateencodeStrayAmpersands(string $text, callable $knownEntity): string#
privatewindows1252(): array#

Decimal references 128 to 159 name Windows-1252 characters, not the C1 controls Unicode puts there; each becomes the reference to the Unicode character it meant, and a code Windows-1252 leaves unassigned is removed. Only the exact unpadded decimal spelling is touched.

@return array<string, string>