1

So basically this is what I want to do:

I have a folder with 100 .txt files, which I listed like this:

$directory = 'files';
$phpfiles = scandir($directory);
foreach($phpfiles as $phpfile)
{
print_r ("<ul><a href=files/$phpfile>".basename($phpfile)."</a></ul><br/>");
}

Each text file contains around 20 lines with different variable names (TEXT;1 TEXT;2 etc.). I want to be able get a separate input field for each line, in order to edit it, and then save the file. I have absolutely no idea how to get extract a single line from a .txt file, or if it's even possible with PHP. Java is also acceptable.

Basically, the lines in the text file looks like this:

TEXT;1;;34;0.0;22.0;105.0
TEXT;2;;34;0.0;22.0;23.0

Any help would be appreciated.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
Peter Noble
  • 675
  • 10
  • 21

1 Answers1

3

Make use of file() in PHP. This function reads your text file in an array line by line.

<?php
$arrbyline=file('yourfilename'));

So you can access each line by $arrbyline[0],$arrbyline[1],... so on Alternatively, you can loop and explode() too

foreach($arrbyline as $lines)
{
 .... // you can explode each element..
}
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126