Read in Text File Line by Line PHP - Newline Not Being Detected

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

This doesn't work for you?

http://us2.php.net/manual/en/filesystem.configuration.php#ini.auto-detect-line-endings

Parsing file in PHP; how to detect newlines?

$file = file("path/to/file.txt");

// Incase you need to call it multiple times ...
function isNewLine($line) {
return !strlen(trim($line));
}

foreach ($file as $line) {
if (isNewLine($line)) {
echo "new line<br/>";
}
}

PHP New Line will not work

Instead of appending \n, concatenate the constant PHP_EOL which is always the correct newline character for the current platform.

It might also be an issue with the program you're using to open the text file with. For instance, Notepad on Windows is incapable of understanding unix style newlines.

PHP newline not working in text file

$numberNewline = $number . "\n";
fwrite($file, $numberNewline);

Try this



Related Topics



Leave a reply



Submit