Detailed explanation of the conversion function of UTF8 binary and plain text strings in PHP

墨辰丷
Release: 2023-03-26 08:44:01
Original
1900 people have browsed it

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.&#39;(二进制UTF-8表示):&#39;.b;
$str_bin=&#39;&#39;;
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=&#39;&#39;;
$str=&#39;&#39;;
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原代码明文
?>
Copy after login


Running results:


16进制的FE表示为2进制是11111110
16进制的FF表示为2进制是11111111
计算机rr我们是谁?(二进制UTF-8表示):
1110100010101110101000011110011110101110100101111110011010011100101110100111001001110010111001101000100010010001111001001011101110101100111001101001100010101111111010001011000010000001111011111011110010011111
计算机as我们是谁?
Copy after login


Related recommendations:

Traditional and Simplified Chinese character converter Traditional and Simplified Chinese conversion class in PHP UTF8 encoding

php utf8 half garbled problem

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template