stc7outlaw
Programmer
I wrote a code to read my text file from my server and my friend tested it and so did I, and it reads upside down. I am a very new PHP programmer. Starting today was my first program. How will I be able to make it so the text file read from top to bottom and displays it on the webpage top to bottom Here is my code that Reads UpSiDeDoWn:
<?php
$filename ="main_news.txt";
$myFile = fopen($filename, "r"
; //open the file for reading, file pointer will be at the beginning of the file
if(! $myFile){ // Make sure the file was opened successfully
print ("File could not be opened."
;
exit;
}
$fcontents = file($filename);
$totalines = count($fcontents); //how many lines of data the file contains
$count = $totalines;
for ($i = 0; $i <= $count; $i++, $totalines--){
$line = ($fcontents[$totalines]);
if($line != ""
{ // if the line from the file is not blank print it
echo "$line ";
}
}
fclose($myFile);
?>
<?php
$filename ="main_news.txt";
$myFile = fopen($filename, "r"
if(! $myFile){ // Make sure the file was opened successfully
print ("File could not be opened."
exit;
}
$fcontents = file($filename);
$totalines = count($fcontents); //how many lines of data the file contains
$count = $totalines;
for ($i = 0; $i <= $count; $i++, $totalines--){
$line = ($fcontents[$totalines]);
if($line != ""
echo "$line ";
}
}
fclose($myFile);
?>