请问这个字符是什么东西?

WBOY
Release: 2016-06-20 12:37:44
Original
1323 people have browsed it

页面显示空格,base64_encode结果:Hw==

类似这种空格有没办法完全过滤掉?我已经用iconv转成gbk再转回来了,还是过滤不了。

$str = iconv('UTF-8', 'GBK//IGNORE', strip_tags($str));$str = iconv('GBK', 'UTF-8//IGNORE', $str)
Copy after login


回复讨论(解决方案)

/** 過濾字符串,保留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;  }  
Copy after login
Copy after login
Copy after login

echo bin2hex(base64_decode('Hw=='));
1f US (unit separator) 单元分隔符

之前做过多年底层开发(汇编、C),不熟悉玩不转

之前做过多年底层开发(汇编、C),不熟悉玩不转



怪不得,原来是高手哇。汇编牛b的都是牛人。

/** 過濾字符串,保留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;  }  
Copy after login
Copy after login
Copy after login



请问,这个正则会不会匹配不到全角的逗号,顿号等汉语标点符号呢?还有斜杠、反斜杠这些会不会过滤掉呢?


/** 過濾字符串,保留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;  }  
Copy after login
Copy after login
Copy after login



请问,这个正则会不会匹配不到全角的逗号,顿号等汉语标点符号呢?还有斜杠、反斜杠这些会不会过滤掉呢?

不会,因为这些都是可以显示的字符。
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