HTML5 with javascript to parse and display a text file

I have an HTML5 page ( index.html ) and I need to display the contents of a .txt file (p001wide.txt). Both are on the server in the same directory.

The text file is generated from the CMS, so I cannot change the format of this file.

The .txt file contains a variable named widetxt . I need to display the contents of a widetxt variable on a page.

What do I need to do to parse a text file and display it in an HTML page?

Do I need to use javascript, and if so, how?


source to share

3 answers

Hm, I found this question that seems similar to yours as far as the file is readable. In terms of parsing, why not use a database like MySQL to store your data? This way you can quickly add and query data.



Just like your index file and the text file you want to read are on the server, you will be able to read the text file on the server and insert what you want from it into the index file using PHP.

See for a tutorial on how this can be done without resorting to a client-side script.

If you cannot change your index file on the server and you can host the PHP file on the server, you can use AJAX to ask your PHP file to read the contents of the text file and return it to you. Then you will use javascript to insert it however you want. I assume you can change the index file because otherwise you could not change its javascript.



You can do this with JavaScript, you basically need to learn how to read and write files (and you specify a variable inside, that will be parsing). Start reading here - other information, just google reads javascript to write files or parses text with javascript.

Good luck!



All Articles