-1

I want print a text file in my php code but it give me the output without multiple lines! think my txt file is this: ( name = doc.txt )

hello guys!
we are here
Lemon is with You!

now my code is:

<?php
$myfile = fopen("doc.txt", "r") or die("Unable to open file!");
echo fread($myfile, 100);
fclose($myfile);
?>

now my problem is my output:

hello guys! we are here Lemon is with You!

I want it in multiple lines! how?

Babak Majdy
  • 55
  • 1
  • 7
  • It is already in that format. Since you are viewing in a browser, \n doesn't make sense to it. Use command line to view it. – nice_dev Dec 08 '20 at 06:32

2 Answers2

1

One solution can be to add the <pre> tag to your output:

echo "<pre>" . fread($myfile, 100) . "</pre>;
Gowire
  • 1,046
  • 6
  • 27
0

Because it can not get whether its new line in file or not so you beed to use\n which produces new line in doc.txt file

hello guys! \n
we are here \n
Lemon is with You!

then

<?php
$myfile = fopen("doc.txt", "r") or die("Unable to open file!");
echo fread($myfile, 100);
fclose($myfile);
?>