mb_encode_numericentity()
mb_encode_numericentity() — Encode character to HTML numeric string reference.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Converts specified character codes in string string from character code to HTML numeric character reference.
Signature
mb_encode_numericentity(string $string, array $map, ?string $encoding = null, bool $hex = false): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string being encoded. |
| $map | array | map is array specifies code area to convert. |
| $encoding | ?string | The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used. |
| $hex | bool | Whether the returned entity reference should be in hexadecimal notation (otherwise it is in decimal notation). |
Return value
The converted string.
Example
A runnable snippet:
$convmap = array( int start_code1, int end_code1, int offset1, int mask1, int start_code2, int end_code2, int offset2, int mask2, // ........ int start_codeN, int end_codeN, int offsetN, int maskN ); // Specify Unicode value for start_codeN and end_codeN // Add offsetN to value and take bit-wise 'AND' with maskN, // then converts value to numeric string reference.
Changelog
| Version | Change |
|---|---|
| 8.4.0 | The mb_encode_numericentity() function now throws a ValueError if map contains any value that cannot be implicitly converted to int. |
| 8.0.0 | encoding is nullable now. |
| 8.0.0 | Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mb_encode_numericentity() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.