#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    8
    Rep Power
    0
    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 '&amp;'.

    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
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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>
    &amp; 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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    8
    Rep Power
    0
    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
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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;

  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    8
    Rep Power
    0
    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

Similar Threads

  1. help with tables and wordwrapping
    By junkedBrian613 in forum PHP Development
    Replies: 2
    Last Post: February 15th, 2004, 06:42 PM
  2. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 07:19 PM
  3. float question
    By yeah-yeah in forum HTML Programming
    Replies: 10
    Last Post: January 15th, 2004, 04:59 PM
  4. Javascript scrollbar - stuck on last bit
    By NayMyoSan in forum JavaScript Development
    Replies: 0
    Last Post: January 3rd, 2004, 01:05 PM
  5. Mouse over questions. n00b. :o
    By Not Tony Danza in forum HTML Programming
    Replies: 2
    Last Post: December 2nd, 2003, 07:28 AM

IMN logo majestic logo threadwatch logo seochat tools logo