Cardale Posted June 11, 2009 Share Posted June 11, 2009 I am trying to get the content from a file and also insert information then display it via a template, but its only displaying the last line. This usually works by assigning the other values to the file...how can I remedy this? function readerrorlog(){ if (file_exists($this->log_file)) { $error_log = fopen($this->log_file, 'r'); $line_number = 0; while ($line = fgets($error_log)){ $line_number++; if($line_number >= 1 && $line != "\n") { $message = $line; $message .= "<br />"; }elseif($line == "\n"){ $message .= "<br /><br />"; }elseif($line_number == 7) { $line_number=0; } } return $message; fclose($error_log); } else { $message = "The file ".$this->log_file." does not exist"; } } Link to comment https://forums.phpfreaks.com/topic/161760-solved-get-file-contents-and-more/ Share on other sites More sharing options...
Cardale Posted June 11, 2009 Author Share Posted June 11, 2009 Got it working function readerrorlog(){ if (file_exists($this->log_file)) { $error_log = fopen($this->log_file, 'r'); $line_number = 0; $array = 0; $message = ""; while ($line = fgets($error_log)){ $line_number++; if($line_number >= 1 && $line != "\n") { $message .= $line; $message .= "<br />"; }elseif($line == "\n"){ $message .= "<br /><br />"; }elseif($line_number == 7) { $line_number=0; } } return $message; fclose($error_log); } else { $message = "The file ".$this->log_file." does not exist"; } } Link to comment https://forums.phpfreaks.com/topic/161760-solved-get-file-contents-and-more/#findComment-853496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.