April 17th, 2000, 03:24 PM
-
Hi,
I am a total novice, so I apologize if this question is silly.
I am trying to setup a very simple site that will pull text files into an existing template. I am using a simple require
statement, such as:
<?php
require "/www/companyname/body.txt"
?>
The first problem is that it does not seem to respect the linefeeds, which are saved in Unix format, and just lists it as one
massive block of text. The second problem is that, obviously, it does not convert symbols such as '&' to '&'.
The reason behind this way of including text into HTML files is so that the lecturers can write articles without having to
deal with HTML and the articles are inserted into the HTML templates with the 'require' statement. Also, the shear
number of text documents that need to be posted would cause a lot of work. I have looked at Project Midguard, but I
tend to shy away from applications with little documentation, even though that would be absolutely ideal.
Any ideas would be really appreciated.
tia
rootdr
April 17th, 2000, 06:26 PM
-
Remember that browsers do not display new lines. You'd have to convert the new lines to <br>.
I don't know what you mean by converting & to &. I thought you might have meant
<code>
& to &
</code>
but that doesn't make sense since you said the text file doesn't contain HTML.
If you want to display a raw text file as HTML you can't do it via require. You'll need to read the file into a variable and do a few things to it such as nl2br() and htmlentities().
Rod
April 17th, 2000, 06:44 PM
-
Hi rod,
This bulletin board parsed my HTML. I am talking about HTML entities, such as how to change '&' to '& a m p ;' (spaces between letters since I don't know how to 'escape' HTML).
thanks
rootdr
April 18th, 2000, 08:02 AM
-
Yes, it did mine as well.
Anyway, I answered your question. htmlentities() is the function you need.
Again, you can't just include() or require() plain text and expect it to display correctly.
Try this:
$fid=fopen("/www/companyname/body.txt",'r');
$plain_text=fread($fid,filesize("/www/companyname/body.txt"));
fclose($fid);
$HTML_safe_text=htmlentities(nl2br($plain_text));
print $HTML_safe_text;
April 18th, 2000, 02:04 PM
-
Rod,
Thanks ever so much for helping me. I had to change:
$HTML_safe_text=htmlentities(nl2br($plain_text));
to
$HTML_safe_text=nl2br(htmlentities($plain_text));
which worked exactly right.
Thanks ever so much, I really appreciate you solving my question. Have a great day!
rootdr