0

I have 5000 rows in text file separated by new line like:

text1
text2
text3
..etc

I need take them one by one from this file as variables in my script, and then result add to file without overwrite last row.

If i trying to paste all array to form and make request like:

$List = preg_split("/\\r\\n|\\r|\\n/", $_REQUEST['text']);
foreach ($List as $text) {
echo (isset($_REQUEST['text']) ? '<pre>' .$exp->result.'</pre>' : $exp->result);
}

it work but wiht less than 100 rows, or server go down.

The questions are:

  1. How take each row from file one by one and make working function ?
  2. How to save the result to file one by one ?
  3. Why does the server overload with my example ?
HamZa
  • 14,671
  • 11
  • 54
  • 75
Valdemar Z
  • 91
  • 1
  • 1
  • 7
  • You say you have the rows in a text file. Why do you use `$_REQUEST` then? – TheWolf Sep 29 '13 at 16:08
  • it work but wiht less than 100 rows, or server go down Server overloads – Valdemar Z Sep 29 '13 at 16:09
  • 1
    That doesn't answer my question. `$_REQUEST` is basically the addition of `$_GET`, `$_POST` and `$_COOKIE`. Why do you access `$_REQUEST` when you want to read from a file? – TheWolf Sep 29 '13 at 16:11
  • Why do you need to test `isset($_REQUEST['text'])` in the loop? If it isn't set, you won't get into the loop. I suspect there's more to your program than you're showing, because this shouldn't cause a server overload. – Barmar Sep 29 '13 at 16:14

1 Answers1

0

This code read data from input file, and put each line to new file.

<?php
$FILE = fopen("data.txt", "r");
$FILEOUT = fopen("outfile.txt","a");
while($line = fgets($FILE))
{
    #add each line to out file
    fwrite($FILEOUT,$line);
}
fclose($FILE);
fclose($FILEOUT);
?>
mNejkO
  • 58
  • 1
  • 4