On Aug 25, 3:48 am, "Bobby" wrote:
> I generate a text file created by a Memo Field in a Delphi application. This
> gets uploaded to my web server to populate a MySql database table.
> The text file uses the '|' (vertical bar) as a delimiter. A typical .txt
> file looks like this:
>
> 1234|4567|My Name|Panasonic|
> Super DeLuxe|Details Bla Bla Bla
>
> I use the explode fuction thus:
>
> $f_array = file("updateclient.txt"); //extract data from file
>
> $ting = explode("|",$f_array[0]);
>
> $job = trim($ting[0]);
> $code = trim($ting[1]);
> $name = trim($ting[2]);
> $make = trim($ting[3]);
> $model = trim($ting[4]);
> $details = trim($ting[5]);
>
> My problem is this:
>
> The explode function terminates(breaks) after array[3] due to the line feed
> (escape) - so that the strings $ting[4] and $ting[5] are empty and the MySql
> table cannot be updated.
>
> If I manually modify the file thus:
> 1234|4567|My Name|Panasonic|Super DeLuxe|Details Bla Bla Bla
> ... into one long line all is OK and obviously the table gets updated.
>
> Any ideas as to how to get the array into all the strings using the file as
> first described?
>
> Hope I have explained clearly enough?
>
> All help appreciated.
You need to break it down by line, as in:
foreach ($f_array as $line_num => $line) {
Then do the exploding on each line, followed by mysql insertion
then it moves on to the next
}
>> Stay informed about: explode()