File: $file"; break; } $fcont = ""; $fd = fopen($file, "rb"); while (!feof($fd)) { $fcont .= fread($fd, 65536); } fclose($fd); if ($_REQUEST[PHP_conv]=="UTF8") { $conv_type = "UTF-8"; print "The $conv_type version
"; $tmpmix = unserialize($fcont); $tmpmix_utf8 = big52utf8($tmpmix); print "
original: ".htmlspecialchars(serialize($tmpmix_utf8))."
"; $tmpmix_utf8_seri_unseri = var_export(unserialize(serialize($tmpmix_utf8)),TRUE); print "
decoded: ".nl2br(htmlspecialchars($tmpmix_utf8_seri_unseri))."
"; } else { $conv_type = "BIG5"; print "The $conv_type version
"; print "Original file content:
$fcont

Decoded file content:


"; $tmp_dec = var_export(unserialize($fcont),TRUE); print "
".nl2br(htmlspecialchars($tmp_dec)); } break; case "convall": foreach ($albumdats AS $key=>$val ) { if (!is_file($val)) { print "The file you request is not exist!
File: $file"; break; } $fcont = ""; $fd = fopen($val, "rb"); while (!feof($fd)) { $fcont .= fread($fd, 65536); } fclose($fd); $utf8str = serialize(big52utf8(unserialize($fcont))); $fd2 = fopen($val, "w"); fwrite($fd2, $utf8str); fclose($fd2); print "

Converted: $val

\n"; ob_flush(); } // end foreach break; default: print "the albumdat list....
"; foreach ($albumdats AS $key=>$val ) { print "$val [ UTF-8]
"; } // end foreach print "
Convert all file from big5 to UTF-8
"; } //end switch ###################################################################################### function big52utf8($big5str) { # Due to iconv is not compiled into PHP default, I use the external iconv program # It's slower, Eat more resources(file) but maybe more compatible. global $iconv_loc; if (is_bool($big5str)||is_numeric($big5str)||is_null($big5str)) { return $big5str; } elseif (is_string($big5str)) { # if str is only ASCII then just return if (preg_match('/^[\x20-\x7E]+$/',$big5str)) { return $big5str; } $tmpfname = tempnam("/tmp","PHPiconv"); $fh = fopen($tmpfname, "wb"); fwrite($fh, $big5str); fclose($fh); $iconv_cmd = "$iconv_loc -c -s -f BIG5 -t UTF-8 $tmpfname"; $outbuf = array(); $utf8str = shell_exec($iconv_cmd); if (!$debug) { unlink($tmpfname); } else { print "[debug] utf8str: $utf8str
"; } return $utf8str; } elseif (is_array($big5str)) { foreach ($big5str AS $key=>$val ) { $big5str[$key] = big52utf8($val); } // end foreach return $big5str; } else { foreach ($big5str AS $key=>$val ) { $big5str->$key = big52utf8($val); } // end foreach return $big5str; } } // end func ?>