Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: kanji-encoding.lib.php,v 2.2 2003/11/26 22:52:23 rabus Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00005 00026 function PMA_internal_enc_check() { 00027 global $internal_enc, $enc_list; 00028 00029 $internal_enc = mb_internal_encoding(); 00030 if ($internal_enc == 'EUC-JP') { 00031 $enc_list = 'ASCII,EUC-JP,SJIS,JIS'; 00032 } else { 00033 $enc_list = 'ASCII,SJIS,EUC-JP,JIS'; 00034 } 00035 00036 return TRUE; 00037 } // end of the 'PMA_internal_enc_check' function 00038 00039 00048 function PMA_change_enc_order() { 00049 global $enc_list; 00050 00051 $p = explode(',', $enc_list); 00052 if ($p[1] == 'EUC-JP') { 00053 $enc_list = 'ASCII,SJIS,EUC-JP,JIS'; 00054 } else { 00055 $enc_list = 'ASCII,EUC-JP,SJIS,JIS'; 00056 } 00057 00058 return TRUE; 00059 } // end of the 'PMA_change_enc_order' function 00060 00061 00074 function PMA_kanji_str_conv($str, $enc, $kana) { 00075 global $enc_list; 00076 00077 if ($enc == '' && $kana == '') { 00078 return $str; 00079 } 00080 $nw = mb_detect_encoding($str, $enc_list); 00081 00082 if ($kana == 'kana') { 00083 $dist = mb_convert_kana($str, 'KV', $nw); 00084 $str = $dist; 00085 } 00086 if ($nw != $enc && $enc != '') { 00087 $dist = mb_convert_encoding($str, $enc, $nw); 00088 } else { 00089 $dist = $str; 00090 } 00091 return $dist; 00092 } // end of the 'PMA_kanji_str_conv' function 00093 00094 00105 function PMA_kanji_file_conv($file, $enc, $kana) { 00106 if ($enc == '' && $kana == '') { 00107 return $file; 00108 } 00109 00110 $tmpfname = tempnam('', $enc); 00111 $fpd = fopen($tmpfname, 'wb'); 00112 $fps = fopen($file, 'r'); 00113 PMA_change_enc_order(); 00114 while (!feof($fps)) { 00115 $line = fgets($fps, 4096); 00116 $dist = PMA_kanji_str_conv($line, $enc, $kana); 00117 fputs($fpd, $dist); 00118 } // end while 00119 PMA_change_enc_order(); 00120 fclose($fps); 00121 fclose($fpd); 00122 unlink($file); 00123 00124 return $tmpfname; 00125 } // end of the 'PMA_kanji_file_conv' function 00126 00127 00136 function PMA_set_enc_form($spaces) { 00137 return "\n" 00138 . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n" 00139 . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n" 00140 . $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n" 00141 . $spaces . ' ' . $GLOBALS['strEncto'] . '<br />' . "\n" 00142 . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n" 00143 . $spaces . ' ' . $GLOBALS['strXkana'] . '<br />' . "\n"; 00144 } // end of the 'PMA_set_enc_form' function 00145 00146 00147 PMA_internal_enc_check(); 00148 00149 ?>