egorig Posted September 7, 2007 Share Posted September 7, 2007 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 More sharing options...
Crow Posted September 7, 2007 Share Posted September 7, 2007 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. Link to comment https://forums.phpfreaks.com/topic/68368-solved-opening-txt-file/#findComment-343804 Share on other sites More sharing options...
egorig Posted September 8, 2007 Author Share Posted September 8, 2007 I was wondering if opening a file line by line is too slow and it's unacceptable. Your suggestion is good , but i want to "bold" the text in capital letters. .And what is going to happen if i try opening larger files (3-4-5 pages) ? Link to comment https://forums.phpfreaks.com/topic/68368-solved-opening-txt-file/#findComment-344318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.