时间:2021-07-01 10:21:17 帮助过:5人阅读
header('Content-type: text/html;charset=utf-8');龙华
$s = '6b6Z5Y2O8K+gpQ==';
echo $t = base64_decode($s), PHP_EOL;
echo bin2hex($t);
header('Content-type: text/html;charset=utf-8');
$s = '6b6Z5Y2O8K+gpTEyMzEyMzEyMw==';
$t = base64_decode($s). PHP_EOL;
echo $t.'
';
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;
}