Why are the same strings encoded differently in PHP?
保哥后院
保哥后院 2019-05-06 12:50:40
0
2
995
header("Content-type:text/html;charset=utf-8");
$secret1 = "rZa9GneIzd9MNyoTv/Ghpk2V6ZHD0KeQC7t0ymEH7cI=";
$secret2 = 'rZa9GneIzd9MNyoTv/Ghpk2V6ZHD0KeQC7t0ymEH7cI=';
$secret3 = 'rZa9GneIzd9MNyoTv/Ghpk2V6ZHD0KeQC7t0ymEH7cI=';

var_dump(trim($secret1));
echo "<br>";
var_dump(trim($secret2));
echo "<br>";
var_dump($secret3);
echo "<br>";
echo mb_detect_encoding($secret1, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
echo "<br>";
echo mb_detect_encoding($secret2, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
echo "<br>";
echo mb_detect_encoding($secret3, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));

The same string displays different codes when detecting the code. What is the problem?

20190506123102.png

保哥后院
保哥后院

漏刻有时,数据可视化大屏。

reply all(1)
Peter-Zhu

There will be different encoding schemes for different character sets. The current one is UTF8

  • reply Thank you Teacher Peter-Zhu. This is an encryption code generated using AES in phpstorm. It is found that the length and encoding method of the string are different during the decryption process. Now in the process of solving programming, how to avoid such problems. Currently, you can use the BOM special invisible characters in the file to clear the function removeBom($string) { if (substr($string, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { return substr($string, 3); } return $string; }
    保哥后院 author 2019-05-07 10:28:21
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template