我在base64
编码和解码方面遇到了一些问题,我想用php解码我的字符串,我找到了一个解决方案,但它效果不佳,我的期望我只想解码已编码的字符串和其他未编码的字符串应该保持正常。
这是一个字符串:
$string = "I need your help 4Z6B4Z+S4Z6b4Z624Z+G4Z6E4oCL4Z6O4Z624Z6f4Z+L4oCL";
这是我尝试过的:
echo base64_decode($string);
结果:
SSBuZWVkIHlvdXIgaGVscA = ខ្លាំងណាស់
上面的结果不是我需要的,下面是我需要的:
I need your help ខ្លាំងណាស់
所以,谁能告诉我如何使用 php 做到这一点。
这应该适合您:
<?php
$str = "I need your help 4Z6B4Z+S4Z6b4Z624Z+G4Z6E4oCL4Z6O4Z624Z6f4Z+L4oCL";
for($count = 0; $count < strlen($str); $count++) {
$temp = substr($str, $count, strlen($str));
if ( base64_encode(base64_decode($temp, true)) === $temp) {
echo substr($str, 0, $count) . base64_decode($str);
break;
}
}
?>