Hi all,
The code below doesn't produce the output I intended. :glare: Can anyone shed some light as to why?
$dataFile = fopen("test.txt", 'r');
$tmpHandle = fopen("test.new.txt", 'w');
$insertPoint="2";
$insertString="Some New Data\r\n";
$lineCount=0;
while (!feof($dataFile)) {
$lineCount++;
if($lineCount == $insertPoint){
fwrite($tmpHandle, $insertString);
continue;
}
fwrite($tmpHandle, fgets($dataFile));
}
fclose($dataFile);
fclose($tmpHandle);
It produces this output:
Data Line 1
Some New Data
Data Line 2
Data Line 3
My intent was that it would produce:
Data Line 1
Some New Data
Data Line 3
I've also tried with an if/else statement in lieu of the continue