Jump to content

Display String Content to Browser


phpnewbieca

Recommended Posts

I am trying to display the content of a text (txt) to the browser. It displays the bold item (title of the page).

then it displays the Date Date Date Date.

 

Please Help!

 

function Guestbk_3() {
  // Display Guestbook Entries to Browser
  global $Date, $Pastor, $Webmaster, $Name, $Church, $City, $State, $Comments, $Alladdresses;
  $MyFile = "guestbook.txt";
  $fh = fopen($MyFile,"r");
  rewind($fh);
  if(!$fh) {
   die("couldn't open file <i>$MyFile</i>");
  }
  else {
   $file = file_get_contents("$MyFile");
  }
  fclose($fh);
  if(strstr($file,$Date)) { 
   echo "<html>\n";
   echo " <head>\n";
   echo " <title>Guestbook Entries</title>\n";
   echo " </head>\n";
   echo " <body BGCOLOR=\"blue\" TEXT=\"white\">\n"; 
   echo " <table align=\"center\">\n";
   echo " <tr>\n";
   echo " <td align=\"center\">\n";
   [b] echo " <font size=\"+2\">~ ~ ~ GUESTBOOK ENTRIES ~ ~ ~</FONT>\n";[/b]
   echo " <br /><br />\n";
   echo " </td>\n";
   echo " </tr>\n";
   echo " </table>\n";
   echo " <table align=\"center\" width=\"600\">\n";
   echo " <tr>\n";
   echo " <td align=\"left\">\n";
[b]   echo " $file\n";[/b]
   echo " </td>\n";
   echo " </tr>\n";
   echo " </table>\n";
   echo " </body>\n";
   echo " </html>";
  }
}

 

Link to comment
https://forums.phpfreaks.com/topic/184482-display-string-content-to-browser/
Share on other sites

I looked at the file and this is what it looks like:

 

 

Mon  07 Dec 2009

 

,

 

 

 

Mon  07 Dec 2009

 

,

 

 

 

Tue  08 Dec 2009

 

,

 

 

 

Tue  08 Dec 2009

 

I do not understand why the other information was not written to the file.  the function Guest_bk() should have written the information to the file guestbook.txt

 

//FUNCTIONS 
function Guestbk_1(){
  // write to file guestbook.txt
  global  $Date, $Name, $Church, $City, $State, $Comments;
  $MyFile = "guestbook.txt";
  $fh = fopen($MyFile,'a+');
  if(!$fh) {
   die("couldn't open file <i>$MyFile</i>");
  }
  else {
   rewind($fh);
   $str = "\n";
   $str.= "\t\t\t\t\t$Date\n";
   $str.= "\t\t\t\t\t$Name\n";
   $str.= "\t\t\t\t\t$Church\n";
   $str.= "\t\t\t\t\t$City\n";
   $str.= "\t\t\t\t\t$State\n";
   $str.= "\t\t\t\t\t$Comments\n"; 
   $str.= "\n"; 
   fwrite($fh, $str);
   echo "success writing to file";
  }
  fclose($fh);
}

function Guestbk_3() {
  // Display Guestbook Entries to Browser
  $MyFile = "guestbook.txt";
  $fh = fopen($MyFile,"r");
  rewind($fh);
  if(!$fh) {
   die("couldn't open file <i>$MyFile</i>");
  }
  else {
   $file = file_get_contents("$MyFile");
  }
  fclose($fh);
  if(strstr($file,$Date)) { 
   echo "<html>\n";
   echo " <head>\n";
   echo " <title>Guestbook Entries</title>\n";
   echo " </head>\n";
   echo " <body BGCOLOR=\"blue\" TEXT=\"white\">\n"; 
   echo " <table align=\"center\">\n";
   echo " <tr>\n";
   echo " <td align=\"center\">\n";
   echo " <font size=\"+2\">~ ~ ~ GUESTBOOK ENTRIES ~ ~ ~</FONT>\n";
   echo " <br /><br />\n";
   echo " </td>\n";
   echo " </tr>\n";
   echo " </table>\n";
   echo " <table align=\"center\" width=\"600\">\n";
   echo " <tr>\n";
   echo " <td align=\"left\">\n";
   echo " $file\n";
   echo " </td>\n";
   echo " </tr>\n";
   echo " </table>\n";
   echo " </body>\n";
   echo " </html>";
  }
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.