Home > Article > Backend Development > Detailed explanation of the conversion function of UTF8 binary and plain text strings in PHP
This article mainly introduces the conversion function of UTF8 binary and plain text strings in PHP, involving operating techniques related to PHP binary and encoding conversion. Friends in need can refer to it
The details are as follows:
<?php define("b", "<br>"); $a = "FE"; $a1 = "FF"; $s = 16; $e = 2; echo $s . "进制的" . $a . "表示为" . $e . "进制是" . base_convert($a, $s, $e) . b; echo $s . "进制的" . $a1 . "表示为" . $e . "进制是" . base_convert($a1, $s, $e) . b; $str = "计算机rr我们是谁?"; $strlen = strlen($str); $n = 0; echo $str.'(二进制UTF-8表示):'.b; $str_bin=''; while ($n < $strlen) { $t = ord($str[$n]); $stra=base_convert($t, 10, 2) ; if(strlen($stra)<8) { $stra="0".$stra; } $str_bin.=$stra; $n++; } echo $str_bin.b;//已经翻译为二进制了 $str_bin="1110100010101110101000011110011110101110100101111110011010011100101110100110000101110011111001101000100010010001111001001011101110101100111001101001100010101111111010001011000010000001111011111011110010011111"; //在此输入二进制,程序编码为明文输出 $chr=''; $str=''; for($i=0;$i<strlen($str_bin);$i++) { $chr.=$str_bin[$i]; if(($i+1)%8==0) { $str.=chr(base_convert($chr, 2, 10)); $chr=NULL; } } echo $str;//二进制的UTF8原代码明文 ?>
Running results:
16进制的FE表示为2进制是11111110 16进制的FF表示为2进制是11111111 计算机rr我们是谁?(二进制UTF-8表示): 1110100010101110101000011110011110101110100101111110011010011100101110100111001001110010111001101000100010010001111001001011101110101100111001101001100010101111111010001011000010000001111011111011110010011111 计算机as我们是谁?
Related recommendations:
Conversion between simplified and traditional Chinese in PHP UTF8 character set
##
The above is the detailed content of Detailed explanation of the conversion function of UTF8 binary and plain text strings in PHP. For more information, please follow other related articles on the PHP Chinese website!