PHP mb_encode_numericentity() Function Last Updated : 11 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The mb_encode_numercentity() function is an inbuilt function in PHP that is used to encode HTML entities with numerical values encoded using either decimal or hexadecimal representation. Syntax: string mb_encode_numericentity( string $string, array $map, string $encoding, bool $hex )Parameters: This function accepts four parameters that are described below. $string: The input string to encode.$map: An array that sets the range of Unicode characters to encode. The array is of the form array (start, end, offset, mask).$encoding: The character encoding of the input and output strings.$hex: An array that sets the range of Unicode characters to encode. The array is of the form array (start, end, offset, mask).Return Values: The mb_encode_numericentity() function returns the encoded string, or "false" if an error occurs. Examples of PHP mb_encode_numericentity() FunctionExample 1: The following program demonstrates the mb_decode_numercentity() function. PHP <?php $text = "I ♥ PHP!"; // Encode special characters as HTML entities $encodedText = mb_encode_numericentity($text, [0x80, 0xffff, 0, 0xffff], 'UTF-8'); echo $encodedText; ?> OutputI ♥ PHP!Example 2: The following program demonstrates the mb_decode_numercentity() function. PHP <?php $text = "Hello, <b>World</b>"; // Array of tags to check for $tagsToEncode = ['<b>', '<strong>', '<i>', '<em>']; // Encode special characters as HTML entities // if the string contains any specified tags foreach ($tagsToEncode as $tag) { if (strpos($text, $tag) !== false) { $encodedText = mb_encode_numericentity( $text, [0x80, 0xffff, 0, 0xffff], 'UTF-8'); break; } else { $encodedText = $text; } } echo $encodedText; ?> OutputHello, <b>World</b>Example 3: The following program demonstrates the mb_decode_numercentity() function. PHP <?php $userContent = "<p>This is a <strong>test</strong> article with some entities.</p>"; // Function to decode HTML entities function decodeUserContent($content) { return mb_decode_numericentity($content, array(0x0, 0x10FFFF, 0, 'UTF-8')); } // Display the user-submitted content safely echo decodeUserContent($userContent); ?> Output <p>This is a <strong>test</strong> article with some entities.</p> Reference: https://www.php.net/manual/en/function.mb-encode-numericentity.php Comment More infoAdvertise with us Next Article PHP mb_encode_numericentity() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Multibyte-String Similar Reads PHP mb_decode_numericentity() Function The mb_decode_numericentity() is an inbuilt function in PHP, where the reference for the numeric string in HTML will be decoded into characters. Syntax: mb_decode_numericentity(string $string, array $map, ?string $encoding = null): stringParameters: This function has four parameters: $string: This p 1 min read PHP | is_numeric() Function The is_numeric() function is an inbuilt function in PHP which is used to check whether a variable passed in function as a parameter is a number or a numeric string or not. The function returns a boolean value. Syntax: bool is_numeric ( $var ) Parameters: The function accepts a single parameter which 2 min read PHP | json_encode() Function The json_encode() function is an inbuilt function in PHP which is used to convert PHP array or object into JSON representation. Syntax : string json_encode( $value, $option, $depth ) Parameters: $value: It is a mandatory parameter which defines the value to be encoded. $option: It is optional parame 2 min read PHP | iconv_get_encoding() Function The iconv_get_encoding() function is an inbuilt function in PHP which is used to retrieve the internal configuration variables of iconv extension. Syntax: mixed iconv_get_encoding( $type = "all" ) Parameters: This function accepts single parameter $type. The value of $type parameter are: all input_e 1 min read PHP htmlspecialchars_decode() Function The htmlspecialchars_decode() function is an inbuilt function in PHP that converts special entities back to characters. Syntax: Sttring htmlspecialchars_decode( string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) Parameters: This function accept two parameters that are discussed 1 min read Like