user3515895
user3515895

Reputation: 59

new line command not working in php

I am trying to write in a text file and after each line is written the next line will be in the new line. But when i check my txt file, it is showing every entry in the same line. Although \t is working, there is a tab in between each field. Here is my code

foreachloop{    
$fp=fopen("order.txt", "a");
fwrite($fp,$item_name."\t".$item_price."\t" .$each_item['quantity']."\t"     .$total_price."\t" .$fname."\n");


    $i++;
}//end of for each loop
fclose($fp);
print "added";

Upvotes: 1

Views: 50

Answers (2)

user1299518
user1299518

Reputation:

Replace "\n" with the defined PHP_EOL

Upvotes: 1

user229044
user229044

Reputation: 239260

Not all operating systems use "\n" as the line delimiter. Use PHP_EOL to insert the end-of-line character(s) appropriate for your operating system.

fwrite($fp, $item_name . "..." . $fname . PHP_EOL);

Upvotes: 4

Related Questions