/** * Test for PMA_Kanji_fileConv * * @return void * @test */ public function testFileConv() { $file_str = "教育漢字常用漢字"; $filename = 'test.kanji'; $file = fopen($filename, 'w'); fputs($file, $file_str); fclose($file); $GLOBALS['kanji_encoding_list'] = 'ASCII,EUC-JP,SJIS,JIS'; $result = PMA_Kanji_fileConv($filename, 'JIS', 'kana'); $string = file_get_contents($result); PMA_Kanji_changeOrder(); $expected = PMA_Kanji_strConv($file_str, 'JIS', 'kana'); PMA_Kanji_changeOrder(); $this->assertEquals($string, $expected); unlink($result); }
/** * Kanji file encoding convert * 2002/1/4 by Y.Kawada * * @param string $file the name of the file to convert * @param string $enc the destination encoding code * @param string $kana set 'kana' convert to JIS-X208-kana * * @return string the name of the converted file */ function PMA_Kanji_fileConv($file, $enc, $kana) { if ($enc == '' && $kana == '') { return $file; } $tmpfname = tempnam('', $enc); $fpd = fopen($tmpfname, 'wb'); $fps = fopen($file, 'r'); PMA_Kanji_changeOrder(); while (!feof($fps)) { $line = fgets($fps, 4096); $dist = PMA_Kanji_strConv($line, $enc, $kana); fputs($fpd, $dist); } // end while PMA_Kanji_changeOrder(); fclose($fps); fclose($fpd); unlink($file); return $tmpfname; }