Page 1 of 2
[SOLVED] Help... Reading files...
Posted: Mon Oct 11, 2004 12:52 am
by d_fx79
Code: Select all
<?php
$file = fopen("test.txt", "r");
$data = fread($file, 1000);
$fixed_data = htmlentities($data);
echo "<pre>$fixed_data </pre>";
?>
-------------
Hi guys, got this problem...- I'm trying to display the "test.txt" file but when it is displayed in the browser, the fonts kinda go to a default font.
I tried taking out the preserve <pre> tags but the content of the "test.txt" was displayed as one chunk of text without any paragraphing (the way i want it to be displayed)
Any ideas how I can around this fellas?
btw, my test.txt has the following contents:
Code: Select all
As an education service provider, we run our own schools, as
well as organise educational clinics and training programmes
related to teaching and learning.
As an education technology consultant, we provide business
solutions and expertise in the niched areas of Education IT
and Infocom Technology, especially in the areas of content
development and content delivery.
Any help is appreciated guys...
Posted: Mon Oct 11, 2004 1:00 am
by feyd
first off, read the bold line in my sig.
[php_man]nl2br[/php_man]()
got it..
Posted: Mon Oct 11, 2004 1:10 am
by d_fx79
Got the message.. Will bear that in mind in future...
anyway got any ideas to my problem?... i can break it off into paragraphs but the displayed text resulted to a default font when I used the code described above...

Posted: Mon Oct 11, 2004 1:16 am
by feyd
you want to change the font? That wasn't very clear, obviously. Adding standard <span> tags around the chunk of text you want to change the font on will allow you to use stylesheet controls to alter the font any-which direction you desire.
Posted: Mon Oct 11, 2004 1:37 am
by d_fx79
<TD colspan="2" vAlign=top><p class="txt"><br>
Code: Select all
<?php
$file = fopen("test.txt", "r");$data = fread($file, 1000);$fixed_data = htmlentities($data);echo "<pre>$fixed_data </pre>";
?>
i already did.. but since i used the
htmlentities function, it displayed the data as an HTML.
Any ideas?
Posted: Mon Oct 11, 2004 1:38 am
by d_fx79
sorry.. i will display the php codes better in the next message

Posted: Mon Oct 11, 2004 1:39 am
by feyd
and you're using htmlentities because.....

Posted: Mon Oct 11, 2004 1:48 am
by d_fx79
well the key reason is because, -as u can see in my test.txt contents- using htmlentities function displays exactly the layout as i want it ... i tried using a normal calling the file and echo it.. but it displayed the content as a big chunk of text in a single paragraph...
Posted: Mon Oct 11, 2004 1:50 am
by feyd
try changing htmlentities to nl2br.
Posted: Mon Oct 11, 2004 1:51 am
by mudkicker
don't use htmlentities, just use nl2br

Posted: Mon Oct 11, 2004 1:54 am
by d_fx79
or is there any other way I can display the data (test.txt) as it is without using htmlentities... iread in one tutorial, by using array to break into a new line... but the result displays the array no 1,2,3,4 .... kinda messy...
Posted: Mon Oct 11, 2004 1:55 am
by mudkicker
you can use file_get_contents() or file()
Posted: Mon Oct 11, 2004 1:56 am
by d_fx79
opps..
Posted: Mon Oct 11, 2004 1:59 am
by d_fx79
you guys are right... tried using the nl2br and it works fine... hey guys thanks.. u rock.... i hope i wasn't a pain.. hehe

Posted: Mon Oct 11, 2004 2:00 am
by mudkicker

No problem, u r welcome