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...)

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.