Read in text file line by line php - newline not being detected Read in text file line by line php - newline not being detected php php

Read in text file line by line php - newline not being detected


What's wrong with file()?

foreach (file($fileName) as $name) {    echo('<tr><td align="center">'.$name.'</td></tr>');}


From the man page of fgets:

Note: If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.

Also, have you tried the file function? It returns an array; each element in the array corresponds to a line in the file.

Edit: if you don't have access to the php.ini, what web server are you using? In Apache, you can change PHP settings using a .htaccess file. There is also the ini_set function which allows changing settings at runtime.