New PHP line in fopen function

0

Well, I've been following a PHP tutorial and everything is fine, but the problem is to write the data in a windows notepad, instead of giving it a new line "\ n", it is putting the data one after the other as if you did not enter, I will post the code and thanks for your help ...

$texto = $date."\t".$tireqty." Pneus \t".$oilqty." Oleo \t "
.$sparkqty." Plugues de velas \t $".$totalamount."\t".$address."\n";

if($arquivo = fopen("carteirainter.txt", 'ab'))
{
    fputs($arquivo, $texto."\n");
    fclose($arquivo);
}
else
    echo "Não foi possivel efetuar a gravaçao.<br>";
    
asked by anonymous 30.09.2015 / 05:47

1 answer

1

Use the PHP_EOL constant:

fputs($arquivo, $texto.PHP_EOL);

Alternatively, you can force this:

fputs($arquivo, $texto."
");

Another way is to use carriage return \ r together with newline \ n:

fputs($arquivo, $texto."\r\n");

It is recommended that the environment be using a UTF8 character set.

Additional note about carriage return and newline compatibility:

\n -> linux
\r -> Mac
\n -> Mac OS-X
\r\n -> Windows
    
30.09.2015 / 06:07