Jump to content

Read file


greenba

Recommended Posts

Hello,

 

I have the following in a file:

   

    1 2008-10-28 16:20:01 1 0 1 0

    2 2008-10-28 16:20:16 1 0 1 0

    1 2008-10-29 06:37:09 1 0 1 0

  11 2008-10-29 07:06:58 1 0 1 0

  44 2008-10-29 07:07:12 1 0 1 0

    2 2008-10-29 07:10:06 1 0 1 0

    3 2008-10-29 13:30:05 1 1 1 0

  15 2008-10-29 13:30:10 1 1 1 0

  24 2008-10-29 13:30:14 1 1 1 0

    3 2008-10-29 13:30:18 1 1 1 0

  15 2008-10-29 13:30:23 1 1 1 0

 

I need to read it line by line and separate each row into 6 variables, so that for the first row;

$var1 = 1

$var2 = 2008-10-28 16:20:01

$var3 = 1

$var4 = 0

$var5 = 1

$var6 = 0

and so on.

 

I have attached a file on how it exactly looks like.

 

Any ideas on how to do this? All help is appreciated

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Or since the file is tab delimited -

 

<?php
$file = "sample.txt";
$lines = file($file);
foreach($lines as $line){
$data = explode("\t",$line);
$data = array_map('trim', $data); // trim any extra tabs/newlines
echo "<pre>",print_r($data,true),"</pre>"; // here is what your data for each line looks like
// put your code here to process the data in each line
}
?>

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.