[英]printf() Extended Unicode Characters?
$formatthis = 219;
$printthis = 98;
// %c - the argument is treated as an integer, and presented as the character with
that ASCII value.
$string = 'There are %c treated as integer %c';
echo printf($string, $formatthis, $printthis);
我试图了解printf()。 我不太了解这些参数。
我可以看到,第一个参数似乎是将应用于格式设置的字符串。
第二个是要格式化的第一个变量,第三个似乎是要格式化的第二个变量。
我不明白的是如何使它打印特殊的Unicode字符。 EG,除了az,AZ,!@#$%^&*(){}“ETC。
另外,为什么将它与字符串中最后一个引号的位置放在一起?
输出:被视为32
How could I encode this in to UTF-16 (Dec) // Snowman = 9,731 DEC UTF 16?
UTF-8 'LATIN CAPITAL LETTER A' (U+0041) = 41, but if I write in PHP 41 I will get ')' I googled an ASCII table and it's showing that the number for A is 065...
ASCII is a subset of UTF-8, so if a document is ASCII then it is already UTF-8
If it's already in UTF-8, why are those two numbers different? Also the outputs different..
编辑,好的,所以我正在查看的图表显然显示了十六进制值中的数字,我没有立即注意到,十六进制中的41是ASCII 065
%c
基本上是int2bin函数,这意味着它将数字格式化为二进制表示形式。 这上升到十进制数255,它将作为字节0xFF
输出。
要输出例如雪人字符☃,您需要输出在选择的编码中表示它所需的确切字节。 如果选择UTF-8对其进行编码,则必需的字节为E2 98 83
:
printf('%c%c%c', 226, 152, 131); // ☃
// or
printf('%c%c%c', 0xE2, 0x98, 0x83); // ☃
您遇到的问题是1)您输出的字节在您将结果解释为的编码中没有任何含义(这意味着在98
的字节目前在UTF-8中没有任何意义,这意味着这就是为什么您看到一个“ ...”和2) echo
printf
结果的原因,该结果输出32( printf
返回其输出的字节数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.