Reputation: 3
When I try to create a file I can't make new line/carriage return. Why is it not working? I tried with :
PHP_EOL
\n
But it is not creating new lines when I look it with notepad
<?php
$file = 'myText.txt';
$id = '1'.$file;
//explode($delimiter, $id);
$content = "<PMTags1.0 win>". PHP_EOL;
$content .= . PHP_EOL;
while($row = mysqli_fetch_array($result))
{
$content .= "<@win:><\<>win>". $row['kategoria'] . PHP_EOL;
$content .= "<@tekst:><\<>tekst><$>";
$content .= $row['text'];
$content .= $gcid.$row['id'].'/'. PHP_EOL;
}
utf8_encode($content);
echo $content;
//Stworzenie pliku
$fp = fopen(trim(trim($id)),"wb");
fwrite($fp,$content);
fwrite($fp, pack("CCC",0xef,0xbb,0xbf));
fopen(trim(trim($id)),"r");
fclose($fp);
//End 4
//5 - Otwarcie pliku
if (file_exists(trim($id))) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename(trim($id)));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize(trim($id)));
ob_clean();
flush();
readfile(trim($id));
exit;
}
Upvotes: 0
Views: 378
Reputation: 9918
For Linux systems the new line character is \n
For Mac systems \r
is enough (Thanks SIT_LCU).
For Windows you must add \r
next to \n
Upvotes: 1
Reputation: 9546
\n = CR (Carriage Return) // Used as a new line character in Unix
\r = LF (Line Feed) // Used as a new line character in Mac OS
\r\n = CR + LF // Used as a new line character in Windows
NewLine
\n is correctly represented in some browsers and tools,
but to get the proper results for all users it is best to use "\r\n" for new line.
Upvotes: 0
Reputation: 7530
PHP_EOL
is "The correct 'End Of Line' symbol for this platform."
But probably you are creating the file on Unix and look at it under Windows - where the EOL
-symbol is different.
Upvotes: 0
Reputation: 130
Don't use PHP_EOL for the output of a textfile, you can better use:
\n\r
For better compatibility
Upvotes: 1