Пример #1
0
 /**
  * 检查object的编码,如果是gbk或者gb2312则尝试将其转化为utf8编码
  *
  * @param mixed $options 参数
  */
 private function authPrecheckObjectEncoding(&$options)
 {
     $tmp_object = $options[self::OSS_OBJECT];
     try {
         if (OssUtil::isGb2312($options[self::OSS_OBJECT])) {
             $options[self::OSS_OBJECT] = iconv('GB2312', "UTF-8//IGNORE", $options[self::OSS_OBJECT]);
         } elseif (OssUtil::checkChar($options[self::OSS_OBJECT], true)) {
             $options[self::OSS_OBJECT] = iconv('GBK', "UTF-8//IGNORE", $options[self::OSS_OBJECT]);
         }
     } catch (\Exception $e) {
         try {
             $tmp_object = iconv(mb_detect_encoding($tmp_object), "UTF-8", $tmp_object);
         } catch (\Exception $e) {
         }
     }
     $options[self::OSS_OBJECT] = $tmp_object;
 }
Пример #2
0
 public function testCheckChar()
 {
     $str = '你好,这里是卖咖啡!';
     $this->assertFalse(OssUtil::checkChar($str));
     $this->assertTrue(OssUtil::checkChar(iconv("UTF-8", "GB2312//IGNORE", $str)));
 }