Hi
I read a text file using PHP, the file gets uplaoded, and what I want to do is read the file take some information out of it and post it to mysql.
Problem is that when reading the file it removes the spaces, I cannot count where the data is as addresses and names in the text file are not the same length.
Code to read the file:
<?php
$data = file_get_contents("tmp/file1.txt"); //read the file
$convert = explode("\n", $data); //create array separate by new line
for ($i=0;$i<count($convert);$i++)
{
echo $convert[$i].', '; //write value by index
}
?>
The process is to to read the file, get the Date, there are lines it needs to read, each line has 4 Items I need, Doc Number, Order number, User and Amount.
The document layout looks like the text documant attached
The fields are in the are place every time, so for example the date will alwys start at a certain character count from the left.
What I am getting so far is all the spaces have been remoevd and everything is in one continous line.
This is a proble when the name is Fred or Alexander the great, the date is ok, but the line data moves around
Here is my result:
Date:2012/10/01 , Contact perosn: Mikee , Contact Number: 0123456789 , , Payee Name :Fred Flinstone , Payee Address :Rocville , :Rock Three , :Stone 172 , , Source Doc Order User Amount , Number Number , --------------------------------------------------------------- , 2134255 004352 Lisa Simpson 4,050.00 , 3321762 337924 Mickey Mouse 702.35 , , ------------ , TOTAL 4,752.35 , ------------ , , ,
Is there a way to pull the spaces trough too, so i can just do a count, or can I read it in another way.
We receive the textfiles as is.
Mike