Home > Backend Development > PHP Tutorial > php怎么读取txt文本内容存入mysql数据库

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

WBOY
Release: 2016-06-13 11:10:03
Original
1583 people have browsed it

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);
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template