Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.