LearningJunkie
New member
With PHP, I'm reading my .txt files using fopen() together with fgets(), but the resulting text on the web page does not show line breaks. It just starts the next line when it runs out of space at the edge of the window. In the text file I have tried creating line breaks using the return key, using \n, and using \r and have not found success with any of these. I've also tried saving as 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!
Alright, so for reference, the text in the file is exactly as follows:
"If you're
reading this,
then you successfully
opened and read
the file.
Good job!
Now, is it apparent where one line ends
and another one starts?"
Taking your advice works. That is, using
$file = fopen("myfile.txt","r");
while(! feof($file))
{
echo fgets($file). "<br>";
}
fclose($file);
It does not, however, show the same line breaks as the original text file. Furthermore the following script ALSO shows the file in exactly the same way:
$file = fopen("myfile.txt", "r");
$text = fgets($file);
echo $text, "<BR>";
It's strange to me that with this script it doesn't stop after the first line break. It looks like the line breaks in my .txt file are just not being recognized. Do you know how we can make them recognized?
Thank you again!
In response to Chapaev:
Alright, so for reference, the text in the file is exactly as follows:
"If you're
reading this,
then you successfully
opened and read
the file.
Good job!
Now, is it apparent where one line ends
and another one starts?"
Taking your advice works. That is, using
$file = fopen("myfile.txt","r");
while(! feof($file))
{
echo fgets($file). "<br>";
}
fclose($file);
It does not, however, show the same line breaks as the original text file. Furthermore the following script ALSO shows the file in exactly the same way:
$file = fopen("myfile.txt", "r");
$text = fgets($file);
echo $text, "<BR>";
It's strange to me that with this script it doesn't stop after the first line break. It looks like the line breaks in my .txt file are just not being recognized. Do you know how we can make them recognized?
Thank you again!
I'm running a mac and using MAMP as my server.
Thank you!
Alright, so for reference, the text in the file is exactly as follows:
"If you're
reading this,
then you successfully
opened and read
the file.
Good job!
Now, is it apparent where one line ends
and another one starts?"
Taking your advice works. That is, using
$file = fopen("myfile.txt","r");
while(! feof($file))
{
echo fgets($file). "<br>";
}
fclose($file);
It does not, however, show the same line breaks as the original text file. Furthermore the following script ALSO shows the file in exactly the same way:
$file = fopen("myfile.txt", "r");
$text = fgets($file);
echo $text, "<BR>";
It's strange to me that with this script it doesn't stop after the first line break. It looks like the line breaks in my .txt file are just not being recognized. Do you know how we can make them recognized?
Thank you again!
In response to Chapaev:
Alright, so for reference, the text in the file is exactly as follows:
"If you're
reading this,
then you successfully
opened and read
the file.
Good job!
Now, is it apparent where one line ends
and another one starts?"
Taking your advice works. That is, using
$file = fopen("myfile.txt","r");
while(! feof($file))
{
echo fgets($file). "<br>";
}
fclose($file);
It does not, however, show the same line breaks as the original text file. Furthermore the following script ALSO shows the file in exactly the same way:
$file = fopen("myfile.txt", "r");
$text = fgets($file);
echo $text, "<BR>";
It's strange to me that with this script it doesn't stop after the first line break. It looks like the line breaks in my .txt file are just not being recognized. Do you know how we can make them recognized?
Thank you again!