18830042010000000000010000010.00
300420101004301512210344 881114065677 john smith 0000010.00
18801062010000000000010000435.20
010620101006011143170683 841208925437 luna barbara 0000435.20
18830062010000000000010001881.00
300620101006302037530018 872420036243 micheal jordan 0001881.00
I have a text file contains information shown above.
I would like to produce a php code where it can read the text file and then insert the extracted data into a database table.
I dont know how to read the data because it contains 3 columns. (Click Toggle Plain Text to see the original).
The database table contains 3 columns which are Transaction ID, Name, Amount.
I just wanna read this data, for example.
300620101006302037530018 87242O036243 MICHEAL JORDAN 0001881.00
The first column is transaction id, 2nd column is name and last one is amount.
How do i separate them? and read all lines inside the text file? and insert them to database.
i try this way. But no luck.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>test</title>
<style type="text/css">
<!--
body, th, td, p, small {
font-family:'Times New Roman',Times,serif;
font-size:100%;
color:#444;
}
small {font-size:90%;}
table {
border:1px solid #ccf;
padding:3px;
}
td, th {
background-color:#def;
padding:7px 20px 7px 20px;
}
th {background-color:#dee; color:#677;}
h1 {font-size:120%; color:#558;}
-->
</style>
</head>
<body>
<table>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Column 6</th>
</tr>
<?php
$fp = fopen('test.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}
$loop = 0;
while (!feof($fp)) {
$loop++;
$line = fgets($fp,1024);
$field[$loop] = explode (' ', $line);
echo '
<tr>
<td>'.$field[$loop][0].'</td>
<td>'.$field[$loop][1].'</td>
<td>'.$field[$loop][2].'</td>
<td>'.$field[$loop][3].'</td>
<td>'.$field[$loop][4].'</td>
<td>'.$field[$loop][5].'</td>
</tr>';
$fp++;
}
fclose($fp);
echo '
</table>';
?>
</body>
</html>
It come out with something like this
http://img718.imageshack.us/img718/3264/nonameye.jpg
Thank you. :)