Function file() php does not pick line by line

Asked

Viewed 199 times

3

I have a system that is going through a problem, one time it reads line by line from a file, but when I send another file of the same type and with the same content (only a few different things) it considers as a line. I’m using the function file() of PHP. The code:

<?php
$lines = file("NET3110123.txt");

foreach($lines as $key=>$line){

    echo '#'.$key.": ".$line.'<br /><br />';
}
?>

With this code he returns to me:

#0: (content...)

And I should return more or less 9500 lines.

This is the file:

https://mega.nz/#! Vylgws6i! Ms_g4alfctx5wbcucxqccjrqf8fj6hp6edeglnyrmw4

  • Is using a mac?

  • I am using Linux

1 answer

5


There is a directive in PHP for automatic line break type detection:

auto_detect_line_endings


Use:

<?php
   ini_set("auto_detect_line_endings", true);

   $lines = file("NET3110123.txt");

   foreach($lines as $key=>$line){
      echo '#'.$key.": ".$line.'<br /><br />';
   }
?>
  • 3

    Woww.. It worked @Bacco ... Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.