[英]Read data from text file with php and create database
I have a text file, a huge one that contains some information's that I need to insert into a database. 我有一个文本文件,其中一个巨大的文件包含一些我需要插入数据库的信息。
Here is the one of the rows of the text file: 这是文本文件的其中一行:
77.242.22.86 - - [10/Jul/2013:14:07:26 +0200] "GET /web/img/theimage.jpg HTTP/1.1" 304 - "http://www.mywebiste.com/web/"
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/27.0.1453.116 Safari/537.36 AlexaToolbar/alxg-3.1"
I am using some php functions like: 我正在使用一些PHP函数,例如:
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
This only read the text file, as I said, I need to get the data and insert into the database, here is an example how I need the row to be spli: 如我所说,这仅读取文本文件,我需要获取数据并将其插入数据库中,这是一个示例我如何需要将行拆分的示例:
77.242.22.86
[10/Jul/2013:14:07:26 +0200]
GET
/web/img/theimage.jpg
HTTP/1.1
304
http://www.mywebiste.com/web/
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/27.0.1453.116 Safari/537.36 AlexaToolbar/alxg-3.1
Please help me to resolve this problem. 请帮助我解决此问题。 Thank you. 谢谢。
$test ='77.242.22.86 - - [10/Jul/2013:14:07:26 +0200]
"GET /web/img/theimage.jpg HTTP/1.1" 304 - "http://www.mywebiste.com/web/"
"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/27.0.1453.116 Safari/537.36 AlexaToolbar/alxg-3.1"';
function tokenizer($test) {
$test = trim(strtolower($test));
$res= str_replace(",","",$test);
$res= str_replace("-","",$res);
$res= str_replace(' "',"",$res);
$result= explode(" ", $res);
for ($i = 0; $i < count($result); $i++) {
$result[$i] = trim($result[$i]);
echo $result[$i]; ?>
<hr/> <?php
}
return $result; // contains the single words
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.