1 頁 (共 1 頁)

utf8.php

發表於 : 2008-08-21 21:15:47
yehlu
<?php
include("common.php");

//sql 轉換
function tosql1($value, $type){
if(!strlen($value)){
return "''";
}else{
if($type == "Number"){
return str_replace (",", ".", doubleval($value));
}else{
$value = str_replace("'","''",$value);
$value = str_replace('"','\"',$value);
$value = str_replace("\\","\\\\",$value);
$value = str_replace("\\'","''",$value);
$value = str_replace("\\\"","\"",$value);
}
return "'" . $value . "'";
}
}

//db1 為 UTF資料庫
$db1 = new DB_Sql();
$db1->Database = "utf8";
$db1->User = "root";
$db1->Password = "";
$db1->Host = "10.10.70.31";

$db1->query("SET NAMES 'UTF8'");

$not_tran = array(
"coupon",
"login_log",
"prod_stock",
"stock_change",
"stock_history"
);

echo "<pre>";
echo date("Y-m-d H:i:s")."<br>";

//讀出所有的資料表

$tables_a1 = $db->table_names();
foreach($tables_a1 as $key => $value){
if(!in_array($value["table_name"], $not_tran)){
$tables_a[] = $value["table_name"];
}
}

foreach($tables_a as $tkey => $table){
//若db1不存在才做
$query1 = "select * from $table";
$db1->query($query1);
if($db1->num_rows()==0){
//讀出所有資料結構
$metadata = $db->metadata($table);
$query = "select * from $table";
$db->query($query);
while($db->next_Record()){
$sql = "insert $table set ";
foreach($metadata as $fkey => $field){
$sql .= $field["name"]." = ".tosql1(iconv("big5","utf-8",$db->f($field["name"])),"Text").",";
}
$sql = substr($sql,0,-1);
//echo $sql."\n";
$db1->query($sql);
}
}
}

echo date("Y-m-d H:i:s")."<br>";
?>

utf8-file.php

發表於 : 2008-09-14 18:16:30
yehlu
<?php

function phpfileedit($file){
$add = 0;
echo $file."<br>";
$fp = fopen("$file","r+");
$old = fread($fp,filesize($file));
$new = iconv("big5","utf-8",$old);
fclose($fp);
if($old<>$new){
$fp1 = fopen("$file","w+");
fwrite($fp1,$new);
fclose($fp1);
}
}

function ListDir($dir){
echo "<UL>";
$handle = opendir($dir);
while ($sdir=readdir($handle)){
if(is_dir("$dir/$sdir") and $sdir<> "." and $sdir<> ".."){
ListDir("$dir/$sdir");
}else{
echo "$sdir<br>";
if(substr($sdir,-3,3)=="php" or substr($sdir,-4,4)=="php3"){
phpfileedit("$dir/$sdir");
}
if(substr($sdir,-3,3)=="htm" or substr($sdir,-4,4)=="html"){
phpfileedit("$dir/$sdir");
}
if(substr($sdir,-3,3)=="ccs"){
phpfileedit("$dir/$sdir");
}
}
}
closedir($handle);
echo "</UL>";
}
ListDir($argv[1]);
?>

utf8-filename.php

發表於 : 2008-09-14 18:17:39
yehlu
<?php
function ListDir($dir){
echo "<UL>";
$handle = opendir($dir);
while ($sdir=readdir($handle)){
if(is_dir("$dir/$sdir") and $sdir<> "." and $sdir<> ".."){
ListDir("$dir/$sdir");
}else{
echo "$sdir<br>";
rename("$dir/$sdir",iconv("big5","utf-8","$dir/$sdir"));
}
}
closedir($handle);
echo "</UL>";
}
ListDir($argv[1]);
?>