21,886
社区成员
发帖
与我相关
我的任务
分享
header('Content-type: text/html;charset=utf-8');
$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';
$t = base64_decode($s). PHP_EOL;
echo $t.'<br>';
echo filter_utf8_char($t);
/** 過濾字符串,保留UTF8字母數字中文及部份符號
* @param String $ostr
* @return String
*/
function filter_utf8_char($ostr){
preg_match_all('/[\x{FF00}-\x{FFEF}|\x{0000}-\x{00ff}|\x{4e00}-\x{9fff}]+/u', $ostr, $matches);
$str = join('', $matches[0]);
if($str==''){ //含有特殊字符需要逐個處理
$returnstr = '';
$i = 0;
$str_length = strlen($ostr);
while ($i<=$str_length){
$temp_str = substr($ostr, $i, 1);
$ascnum = Ord($temp_str);
if ($ascnum>=224){
$returnstr = $returnstr.substr($ostr, $i, 3);
$i = $i + 3;
}elseif ($ascnum>=192){
$returnstr = $returnstr.substr($ostr, $i, 2);
$i = $i + 2;
}elseif ($ascnum>=65 && $ascnum<=90){
$returnstr = $returnstr.substr($ostr, $i, 1);
$i = $i + 1;
}elseif ($ascnum>=128 && $ascnum<=191){ // 特殊字符
$i = $i + 1;
}else{
$returnstr = $returnstr.substr($ostr, $i, 1);
$i = $i + 1;
}
}
$str = $returnstr;
preg_match_all('/[\x{FF00}-\x{FFEF}|\x{0000}-\x{00ff}|\x{4e00}-\x{9fff}]+/u', $str, $matches);
$str = join('', $matches[0]);
}
return $str;
}
header('Content-type: text/html;charset=utf-8');
$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';
$t = base64_decode($s), PHP_EOL;
echo bin2hex($t);
e9be99e58d8ef0afa0a5313233313233313233
不是跟你说了吗?那是表情符,PC 中的浏览器都是不会显示的header('Content-type: text/html;charset=utf-8');
$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';
echo $t = base64_decode($s), PHP_EOL;
echo pack("H*", bin2hex($t));
这样的就不行诶~~ 而且中间应该不是空格
header('Content-type: text/html;charset=utf-8');
$s = '6b6Z5Y2O8K+gpQ==';
echo $t = base64_decode($s), PHP_EOL;
echo bin2hex($t);
龙华