コード例 #1
0
/**
 * Converts encoding of file according to parameters with detected
 * conversion function. The old file will be unlinked and new created and
 * its file name is returned.
 *
 * @param   string   source charset
 * @param   string   target charset
 * @param   string   file to convert
 *
 * @return  string   new temporay file
 *
 * @access  public
 *
 * @author  nijel
 */
function PMA_convert_file($src_charset, $dest_charset, $file)
{
    switch ($GLOBALS['PMA_recoding_engine']) {
        case PMA_CHARSET_RECODE:
        case PMA_CHARSET_ICONV:
        case PMA_CHARSET_LIBICONV:
            $tmpfname = tempnam('', 'PMA_convert_file');
            $fin = fopen($file, 'r');
            $fout = fopen($tmpfname, 'w');
            if ($GLOBALS['PMA_recoding_engine'] == PMA_CHARSET_RECODE) {
                recode_file($src_charset . '..' . $dest_charset, $fin, $fout);
            } else {
                while (!feof($fin)) {
                    $line = fgets($fin, 4096);
                    if ($GLOBALS['PMA_recoding_engine'] == PMA_CHARSET_ICONV) {
                        $dist = iconv($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $line);
                    } elseif ($GLOBALS['PMA_recoding_engine'] == PMA_CHARSET_ICONV_AIX) {
                        $dist = PMA_aix_iconv_wrapper($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $line);
                    } else {
                        $dist = libiconv($src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $line);
                    }
                    fputs($fout, $dist);
                }
                // end while
            }
            fclose($fin);
            fclose($fout);
            unlink($file);
            return $tmpfname;
        default:
            return $file;
    }
}
コード例 #2
0
ファイル: Extrecode.01.php プロジェクト: exakat/exakat
<?php

$input = fopen('input.txt', 'r');
$output = fopen('output.txt', 'w');
recode_file("us..flat", $input, $output);