[SOLVED] Help... Reading files...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

[SOLVED] Help... Reading files...

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

first off, read the bold line in my sig.

[php_man]nl2br[/php_man]()
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

got it..

Post 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... :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

Post 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?
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

Post by d_fx79 »

sorry.. i will display the php codes better in the next message :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

and you're using htmlentities because..... :?:
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try changing htmlentities to nl2br.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

don't use htmlentities, just use nl2br :?:
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

Post 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...
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

you can use file_get_contents() or file()
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

Post by d_fx79 »

opps..
d_fx79
Forum Newbie
Posts: 9
Joined: Mon Oct 11, 2004 12:50 am
Location: Singapore

Post 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 :)
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

;) No problem, u r welcome
Post Reply