set_time_limit(0);
error_reporting(0);
ignore_user_abort(true); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
//ini_set("memory_limit","100M");
require 'config.inc.php';
require '../common.inc.php';
mysql_query("set names utf-8");
//表名
$result = $db->query("SELECT company_name from www3");
while($r = mysql_fetch_assoc($result)){
$return_array[] = $r;
}
$db->free_result($result);
//处理字符串中包含(|| ,)
$compamy = arrToStr($return_array);//分割成字符串
$company_array = explode("||",$compamy);//字符串转换成数组
$ywcom = implode(",",$company_array);//数组转化成字符串
$szcom = explode(",",$ywcom);//字符串转换成数组
$i = 0;
foreach ($szcom as $k=>$v){
$r[cate] = into_cate($v);
$i++;
}
echo "插入表成功!共插入了".$i." 条";
exit;
function into_cate($v){
global $db;
$res = $db->query("insert
into www4_company (company)values('$v')");
return
1; }
//将二维数组循环成字符串
function arrToStr($array){
static $r_arr = array();
if(is_array($array)){
foreach($array as $key => $value){
if(is_array($value)){
arrToStr($value);
} else{
$r_arr[] = $value;
}
}
}else if(is_string($array)){
$r_arr[] = $array;
}
$r_arr = array_unique($r_arr);
$string= implode(",",$r_arr);
return $string;
}