Jump to content

how do I get text text data from a ".dat" file and work with it?


xwishmasterx

Recommended Posts

hello

 

I have a ".dat" file that contains looks like this:

 

500,1000,1000,,2000,
400,800,800,,1000,
300,600,600,,750,
200,400,400,,500,
100,200,200,,300,
,,,,,

 

How can I  retrive these values and work with them? (eg: UPDATE * SET points= 500 from the top row, other_points=300 from the last row...)

TEST.DAT

500,1000,1000,,2000
400,800,800,,1000
300,600,600,,750
200,400,400,,500
100,200,200,,300

 

Example code:

<?php
$fh = fopen('test.dat', 'r');
$data = array();
while ($line = fgetcsv($fh, 1024))
{
    $data[] = $line;
}
fclose($fh);

$lastline = count($data) - 1;
$lastitem = count($data[$lastline]) - 1;

echo "First data item : {$data[0][0]}<br />";                             // 500
echo "Last data item : {$data[$lastline][$lastitem]}<br />";      // 300
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.