HTML - Read a text file, edit it and write changes

Discussion in 'Programming' started by Kila, May 30, 2012.

to remove all ads.
  1. Kila

    Kila New Member

    Messages:
    2
    I have a text file that contains a list of email addresses, each on a new line. I want to load this text file using HTML and have the contents displayed. I also want to be able to edit the text file on the webpage and have it write any changes.

    This just needs to be very simple, nothing fancy. It has to be HTML or JavaScript. Any Google results generally use PHP.

    I'm guessing the writing part might not be possible without using PHP or something, but what about just simply reading the text file and displaying it? What would be the simplest HTML code to do that?

    Thanks!
     
    Last edited: May 30, 2012
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,638
    Webservers use PHP not Google

    100% correct.

    Neither will work, HTML has no scripting and javascript cannot read remote files.

    server side includes (SSI).
    Provided that your server is setup for SSI on .htm(l) file extensions that is.
     
  3. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,638
    Oh! and.

    HTML does not display "new lines" from text files, the entries would have to be seperated by a <br> which is an HTML line-break. That could be done with with javascript by inserting line-breaks into the DOM when the page loads, provided you include the text file into an element with a preset ID.
     
  4. Kila

    Kila New Member

    Messages:
    2
    Thanks for the reply, guess PHP it is!

    And the Google comment - I meant when I searched for this question, the only results that were related to what I wanted to do were for PHP!
     
  5. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,638
    Aha I see.

    If you have PHP available you can simply read in the file contents, pass it through nl2br() and push it out in the data stream. job done.

    Just be aware that is this is on a public URL spam bot harvesters will be able to collect the email addresses.
     

Share This Page