Jump to content

[SOLVED] Opening TXT file


egorig

Recommended Posts

Hi there,

I was wondering if it's too slow to use this

		function openFile($filename)
	{
		$file = fopen($filename,'r');

		while (!feof($file))
		{
			$line = trim(fgets($file));
			if ($line == strtoupper($line) AND $line <> '')
				echo "
				<span class = \"bold\">".$line."</span><br/>";
			else
				echo '
				'.$line.'<br/>';
		}
	}

 

I don't want to include the file - "include 'filename.txt', because everything goes on one line. Using

<pre> </pre>

tag is not an option too.. Displaying small texts with the function above is not slow, but if i use texts with 4-5 pages?? Is it proper to use this function. Is there another way ?

Link to comment
https://forums.phpfreaks.com/topic/68368-solved-opening-txt-file/
Share on other sites

I'm not 100% sure on what you're asking.

 

<?php
function open_file($file) {
$hand = fopen($file,'r');
$read = fread($hand,filesize($file));
$read = nl2br($read);
return $read;
}

echo open_file('somefile.txt');
?>

 

Opens the file, reads it, converts all \n (newlines) into line breaks and stores it into $read.

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.