\ n does not work in my fwrite ()

Not sure what might be the problem.

I flush the data from the array $theArrayto theFile.txt, each element of the array on a separate line.

$file = fopen("theFile.txt", "w");
foreach ($theArray as $arrayItem){
    fwrite($file, $arrayItem . '\n');
}
fclose($file);

The problem is , when I open theFile.txt, I see what \nis displayed literally. Also, if I try to programmatically read a file line by line (just in case, lines there), it shows them as 1 line means they \nreally don't have the desired effect.

+5
source share
2 answers

Include \nin double quotes as"\n"

a \n , n, char.

+8

. "$" , ( . , "\n" .

+2

All Articles