making a paragraph in html contain a text from a file

You can do something like that in pure html using an <object> tag:
<div><object data="file.txt"></object></div>

This method has some limitations though, like, it won't fit size of the block to the content - you have to specify width and height manually. And styles won't be applied to the text.


It can be done with HTML <embed> or <object> tags, Javascript, or PHP/ASP/other back-end languages.

PHP (as example of server-side language) is the the way I've always done it:

<div><p><?php include('myFile.txt'); ?></p></div>

To use this (if you're unfamiliar with PHP), you can:

1) check if you have php on your server

2) change the file extension of your .html file to .php

3) paste the code from my PHP example somewhere in the body of your newly-renamed PHP file


You can use a simple HTML element <embed src="file.txt"> it loads the external resource and displays it on the screen no js needed

Tags:

Html