Jump to content

[SOLVED] Assigning Lines of a Files to an Array


suttercain

Recommended Posts

Hey everyone,

 

I am using the following code to extract a file into an array:

<?php

// set file to read
$file = 'http://localhost/PHP%20Tutorials/By%20Example/examples/chapter10_examples/datebook.bck';
// read file into array
$data = file($file) or die('Could not read file!');
// loop through array and print each line
foreach ($data as $line) {
     echo $line . "<br>";
}

?> 

 

How would I assign the "lines of a file" to this code? What I mean, right now it outputs 20 lines of code and breaks them into name, street, etc.

 

I would like it to output the numeric lines of that file. So 1. name, street, etc. 2. name, street, etc.

 

Thanks in advance.

 

 

Shannon

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.