Use
chr($i)The ASCII can be printed smoothly, however, when $i>=19968 (the Unicode starting value of the Chinese character is 4E00 decimal), it is not possible to print out the characters.
Such as:
Although there are other methods, such as:
//代码2$character = html_entity_decode('一', ENT_QUOTES, 'UTF-8');
But why doesn't code 1 print out Chinese characters?
Reply content:
The use chr($i) can print out the ASCII smoothly, however, when $i>=19968 (the Unicode starting value of the Chinese character 4E00 decimal), found unable to print out the Chinese characters.
Such as:
Although there are other methods, such as:
//代码2$character = html_entity_decode('一', ENT_QUOTES, 'UTF-8');
But why doesn't code 1 print out Chinese characters?
ASCII does not contain Chinese characters at all,
It is gb2312-80,gbk,big5,unicode that contains Chinese characters.
Chinese characters are multibyte, and you'll find out with Ord that only the first byte of the kanji will be returned.
In fact, the source of the CHR function is/ext/standard/string.c
The code is as follows
PHP_FUNCTION(chr)
{
Long C;
Char temp[2];
if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT;}if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "l", &c) == FAILURE) { c = 0;}temp[0] = (char)c;temp[1] = '\0';RETURN_STRINGL(temp, 1, 1);
}
As you can see, it is the character cast of the C language.