Jump to content

[SOLVED] get file contents and more


Cardale

Recommended Posts

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

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";
	}
}

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.