コード例 #1
0
ファイル: SplitWord.class.php プロジェクト: happyun/tuan
 /**
  * 导出词典的词条
  * @parem $targetfile 保存位置
  * @return void
  */
 static private function ExportDict($targetfile) {
     if (!self::$mainDicHand) {
         self::$mainDicHand = fopen(self::$mainDicFile, 'rw');
     }
     $fp = fopen($targetfile, 'w');
     for ($i = 0; $i <= self::$mask_value; $i++) {
         $move_pos = $i * 8;
         fseek(self::$mainDicHand, $move_pos, SEEK_SET);
         $dat = fread(self::$mainDicHand, 8);
         $arr = unpack('I1s/n1l/n1c', $dat);
         if ($arr['l'] == 0) {
             continue;
         }
         fseek(self::$mainDicHand, $arr['s'], SEEK_SET);
         $data = @unserialize(fread(self::$mainDicHand, $arr['l']));
         if (!is_array($data))
             continue;
         foreach ($data as $k => $v) {
             $w = iconv(UCS2, 'utf-8', $k);
             fwrite($fp, "{$w},{$v[0]},{$v[1]}\n");
         }
     }
     fclose($fp);
     return TRUE;
 }