mb_decode_numericentity
(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_decode_numericentity — Декодирует числовую HTML-ссылку в символ
Описание
string mb_decode_numericentity
( string
$str
, array $convmap
[, string $encoding
= mb_internal_encoding()
] )
Преобразует строку чисел string
str
в заданном блоке в символ.
Список параметров
Возвращаемые значения
Преобразованная строка string.
Примеры
Пример #1 Пример convmap
<?php
$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 );
// Задайте значения Юникода для start_codeN и end_codeN
// Добавьте к значению offsetN и сложите побитово с maskN,
// затем преобразуйте результат в число.
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Поддержка языков и кодировок
- Многобайтные строки
- mb_check_encoding
- mb_convert_case
- mb_convert_encoding
- mb_convert_kana
- mb_convert_variables
- mb_decode_mimeheader
- mb_decode_numericentity
- mb_detect_encoding
- mb_detect_order
- mb_encode_mimeheader
- mb_encode_numericentity
- mb_encoding_aliases
- mb_ereg_match
- mb_ereg_replace_callback
- mb_ereg_replace
- mb_ereg_search_getpos
- mb_ereg_search_getregs
- mb_ereg_search_init
- mb_ereg_search_pos
- mb_ereg_search_regs
- mb_ereg_search_setpos
- mb_ereg_search
- mb_ereg
- mb_eregi_replace
- mb_eregi
- mb_get_info
- mb_http_input
- mb_http_output
- mb_internal_encoding
- mb_language
- mb_list_encodings
- mb_output_handler
- mb_parse_str
- mb_preferred_mime_name
- mb_regex_encoding
- mb_regex_set_options
- mb_send_mail
- mb_split
- mb_strcut
- mb_strimwidth
- mb_stripos
- mb_stristr
- mb_strlen
- mb_strpos
- mb_strrchr
- mb_strrichr
- mb_strripos
- mb_strrpos
- mb_strstr
- mb_strtolower
- mb_strtoupper
- mb_strwidth
- mb_substitute_character
- mb_substr_count
- mb_substr
Коментарии
Just two great functions for daily use:
/* Converts any HTML-entities into characters */
function my_numeric2character($t)
{
$convmap = array(0x0, 0x2FFFF, 0, 0xFFFF);
return mb_decode_numericentity($t, $convmap, 'UTF-8');
}
/* Converts any characters into HTML-entities */
function my_character2numeric($t)
{
$convmap = array(0x0, 0x2FFFF, 0, 0xFFFF);
return mb_encode_numericentity($t, $convmap, 'UTF-8');
}
print my_numeric2character('’ ἀ â');
print my_character2numeric(' ? ? ');
note that at this time it seems that mb_decode_numericentity() only works with decimal entities and not hexadecimal entities. This fact would have saved me a good hour of time in debugging.
For those who need to convert hex entities try first converting them all to decimal entities with a combination of the preg_replace() and hexdec() functions.
Be careful!
In addition to translate numeric entities to chars on specified target encoding, this function encodes every character from input string to the specified target encodin, even if the characters are outside the range defined by the conversion map.
<?php
// the following documentation depending on understanding of the code source of php mbr
// first in order to optimise the work of php
// the string must contain "&" or else php won't bother trying to decode.
// for the map : int start_codeN, int end_codeN, int offsetN, int maskN
// the entity must be in the range [start_codeN, end_codeN] , if the entity is greater or less
// mb_decode_numericentity will ignore the decode process and return the $string as it is.
// in the late version of php, $map : "must have a multiple of 4 elements"
$map = [ 0x0, 0xFFFF, 0, 0];
echo mb_decode_numericentity('m', $map ); // result "m"
// if offsetN = 1 result "l" ; the more you increase the decimal the more it use OR operrand.
$map_2 = [ 0x0, 0xFFFF, 60, 0];
echo mb_decode_numericentity('m', $map_2 ); // decode ( 1 ) result : "1"
// entity Reference to check the result : https://cs.stanford.edu/people/miles/iso8859.html#ISO
?>