Displaying a .txt file in a web page...

Imagine you have a client (Wahoo!!!) who clearly doesnt know html (If they did, why would they be your client? lol) but they want to be able to update the content of the site themselves...
I can't use a CMS, way to much bother... So... I want to be able to have a .txt file whcih is displayed on the site. So if for example, there is an index.html page and a index.txt page, I want to put something that means "Display index.txt here, in xx font and xx size" so then the client just edits the txt file and voila!

Help!
«1

Comments

  • tntcheatstntcheats Senior Member The Royal RAM
    Well, if they don't require any pages to ever be added, you can simply include the TXT file via a simple PHP script.

    <?php include("fileurl.txt"); ?>

    This requires that PHP is installed on the server; it won't work on Geocities or any of the other retarded hosts which don't include PHP.
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    Hey! What do you take me for?
    I stopped using geocities ages ago! lol...
    But thanks.

    So, all I do to get the .txt file on the page is just put taht tiny bit of code wherever I want to text to be?

    And If they edit the .txt dile the site will automatically update itself and all?
  • tonytony Moderator Administrator
    try the code out
    but yea it should change
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    And Does it have to be a .txt? What about a .rtf or a word document?
  • tonytony Moderator Administrator
    i dont think they would work as the formatting would display as it should, like if you put text in blue it would still come up as times new roman in black unless you used the font tags in it so that would make it pointless to use rtf or .doc, but im not saying they wont work as ive never tried
  • tonytony Moderator Administrator
    *wouldnt display as it should, sorry
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    okay. thanks...
    And how do I change the font etc from in the html document...
    So, the .txt file is all in starnrad black text...
    What If I want to make it bigger or change the colour from within the html file...
    How do I do that?
  • tonytony Moderator Administrator
    it will all be in standard black anyway, you could either change the font by editing the CSS which your client probably wouldnt be able to do unless they know a bit, or they would have to use the font tags in their document
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    I will be doing it, not the client...
    So I just put a bit of css like font-color:FF0000 into the div tag and that will still edit how the text from the .txt looks on the webpage? Even though there is PHP involved etc?
  • tonytony Moderator Administrator
    it should do, in theory but ive never tried it :oops:
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    Ok. :) I'm working on it now ;)
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    Okay... How can I make the whole lot align to the middle? The the align thing for div tags is depreciated...
  • PythonPython Forum Leader The Royal RAM
    just a little suggestions: wouldnt it be easier just to include a file such as index_edit.htm

    that html file could then contain the content which needs to be edited but get rid of all head, body and any other tags and tell your client to edit it using notepade and to use <br> to go to the next line.

    also then you could maybe write a small readme and tell him how to do div tags, their not that hard

    The Royal Ram

  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    Yeah... but what if the client is not willing to learn any of this?
    Plus The other one is quicker... Just paste one line in the html and make a new .txt file for every html file... which is bout 5.... lol
  • PythonPython Forum Leader The Royal RAM
    yeh true, hehe

    The Royal Ram

  • tntcheatstntcheats Senior Member The Royal RAM
    An RTF document theoretically will not work, as if you try to open it online then I believe it opens in Wordpad, or whatever your default is (MS Word, Openoffice.org, etc)

    I believe that the problem with this, is that it will simply include the exact text file directly into the HTML. So if you have

    [code:1:ac2f3d3496]Hello

    World[/code:1:ac2f3d3496]
    With the spaces in it in your text file, like regular un-formatted text in HTML it will show directly beside it.
    [code:1:ac2f3d3496]Hello World[/code:1:ac2f3d3496]
    Including a file will put the EXACT CONTENTS of the file DIRECTLY into the page. It is as if it was typed right into the page.

    if the client doesn't want to use a CMS they could also use something like (WYSIWYG) Mozilla Composer which comes with the browser Mozilla (not Firefox, I don't believe, sorry).
  • JayDesignsJayDesigns Beginner Link Clerk
    Hey, my first reply!

    The best way to solve that problem would be to actually read the content of the text file rather than just include it. Then u can replace the breaks in the text file with a br tag!

    [code:1:e5d44a4527]
    $file = "textfile.txt";
    $do = fopen($file, "r");
    $data = fread($do, filesize($file));
    fclose($do);
    echo $data;
    [/code:1:e5d44a4527]

    Now you'll have to excuse me I've forgotten how to replace characters... I could guess but I'd probably be wrong.
    Anyway, by using this you can do alot more things like separate the text by using a delimiter and being able to place certain bits of text in different places, in a different order, etc.
    JayDesigns.co.uk
  • PythonPython Forum Leader The Royal RAM
    maybe you could search the functions at php.net for how to replace text

    The Royal Ram

  • pfgannonpfgannon Moderator Administrator
    ive always wondered about this thanks for posting the question CBG.
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    So with the php include thing that tnt said, Any returns in the .txt file won't show up on the site?
  • tntcheatstntcheats Senior Member The Royal RAM
    Sadly, no.

    I don't know about SSI, however. Can someone clarify, please?

    <!--#include virtual="/path/to/file/filename.txt" -->
  • JayDesignsJayDesigns Beginner Link Clerk
    yup tntcheats, thats correct. ensure the page is saved with extension .shtml
    JayDesigns.co.uk
  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    So I save the home page as index.Shtml and put:
    <!--#include virtual="/path/to/file/filename.txt" -->
    where I want the text to go, and that's it?
  • PythonPython Forum Leader The Royal RAM
    yup thats right

    index.shtml

    **No capital letters

    The Royal Ram

  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    Yeah... kk... I only put capital s because I was to lazy to put in the bbcode to make it bold... lol
  • PythonPython Forum Leader The Royal RAM
    now that is the definition of lazy ^^

    The Royal Ram

  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    yep.
    But what would you do. Press shift S? or type [ b ] s [ / b ] ? :P lol
  • PythonPython Forum Leader The Royal RAM
    ye id prefer the shift and s

    The Royal Ram

  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    I rest my case... :P
  • tntcheatstntcheats Senior Member The Royal RAM
    Don't forget to change the path to the filename, because I don't think that it'll have
    path/to/ as the directory.
Sign In or Register to comment.