i can't seem to find a neat way of reading a file into an array line by line...
all the examples on the net are really messy and overkilled, basically, i have a text file with a tag on each line:
<img tag="xyz.jpg">
<img tag="123.jpg">
<img tag="abc.jpg">
and that is all thats in the file...
i want some php to look at this file and put the first line in array[0] the second in array[1] etc...
there seems to be lots of ways of doing it that include fgets, explode, and loads of other functions, could someone just show me the slickest way to do this i'm sure it doesn't need to be as complicated as everyone makes it look...
any ideas?
wont something dead simple like this work?
all the examples on the net are really messy and overkilled, basically, i have a text file with a tag on each line:
<img tag="xyz.jpg">
<img tag="123.jpg">
<img tag="abc.jpg">
and that is all thats in the file...
i want some php to look at this file and put the first line in array[0] the second in array[1] etc...
there seems to be lots of ways of doing it that include fgets, explode, and loads of other functions, could someone just show me the slickest way to do this i'm sure it doesn't need to be as complicated as everyone makes it look...
any ideas?
wont something dead simple like this work?
Code:
<?php
$myFile = "YourFile.txt";
$handle = fopen($myFile, 'r');
while (!feof($handle))
{
$data[] = fgets($handle, 512);
}
fclose($handle);
?>
Last edited: