PHP头条
热点:

php怎么读取txt文本内容存入mysql数据库


php如何读取txt文本内容存入mysql数据库!
本帖最后由 pigpighappy 于 2012-12-17 17:07:47 编辑 求大神解答啊!php如何读取txt文本内容存入mysql数据库呢?求完整代码!合适可加分!小女子谢过了!
------解决方案--------------------
这个要看你的txt 里面是不是按数据库字段方式写的如果是就好办,我是这样做,我用txt添加的是邮件地址
每行只要求一个地址

//上传txt文本
if($_FILES['text']['name']){   
$path='../upload';
if(!file_exists($path)){
mkdir($path);
}
if(!is_dir($path)){
mkdir($path);
}
$p=strrchr($_FILES['text']['name'],'.');
if(preg_match("/txt/",$p)){
$file=$path.'/'.date('Ymd').time().$p;
move_uploaded_file($_FILES['text']['tmp_name'],$file);
     
$get=fopen($file,'r');
$j=0;
while (!feof($get)){                   //循环读取每一行
$row=fgets($get);
$row=str_replace(' ','',$row);
$rowa=preg_match("/\@/",$row);
$sql="INSERT INTO `address`(`address`,`timees`,`data`)VALUES('".$rowa."','0',1)";
$db->guery($sql);
$j++;
    }

}
echo"《script》alert('已經添加$j條');history.back();《script》";
}
}else{
echo"《script》alert('选择正确添加方式 ');history.back();《script》";
}
fclose($get);

www.phpzy.comtrue/phprm/13782.htmlTechArticlephp怎么读取txt文本内容存入mysql数据库 php如何读取txt文本内容存入mysql数据库! 本帖最后由 pigpighappy 于 2012-12-17 17:07:47 编辑 求大神解答啊!php如何读取txt文本内容存入mysql数据库呢?求...

相关文章

相关频道:

PHP之友评论

今天推荐