How do I create line breaks in a .txt file that PHP can read?

LearningJunkie

New member
I am learning PHP and have a file called myfile.txt that I would like to read with PHP. The contents of the file is as follows:

"If you're
reading this,
then you successfully
opened and read
the file.
Now, why isn't it apparent where
one line ends
and another one starts?"

The code I use is as follows:

$handle = fopen("myfile.txt", "r");

$text = fgets($handle);
echo $text, "<BR>";

This code echoes the entire text file! It runs it as one line that wraps at the edge of the window. I would expect it to stop, however, after the first line of the file.

My theory is that the line breaks in the text file are not recognized. I have tried creating line breaks using the return key (shown above), using \n, and using \r and have not found success with any of these. I've also tried saving (from Microsoft Word) as a text document with line breaks and as a text document without line breaks. What am I missing?

I'm running a mac and using MAMP as my server.

Thank you!
 
Back
Top