how do you display a file in html?

2    21 Nov 2019 12:40 by u/RustyEquipment

Let's say im doing a blog type post, where i want to be able to write the post in text pad (no fancy formatting) and then either save it to DB or save it on FTP while being able to pull the 'source code' out of it and then format it and post it to html...

ive having a brain fart on best route for doing that....

12 comments

0

Try this in a .php file:

<?php

echo file_get_contents("text.txt");

0

Does embed do what you are looking for? I'm not sure how you want to retrieve it from the DB but this should display it easily.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed

0

I am not sure... possible. I think that will help me with other ideas i have with vidya and whatchamacallits

copied this from another reply:

ideally i would be able to just read the file into a <div> and then use some php to manipulate it and format if needed.

http://baby.rustyequipment.com/pages/blog.html

so i could write a file formatted like each of those blocks, but i would just load the page for it to 'read' the file

0

Making sure I understand what you want to do exactly...

So you'd write a post in plain text, then save it to a server either as a flat file or inside of a database, then post it as an html file that would display the content properly in a web browser?

0

ideally i would be able to just read the file into a <div> and then use some php to manipulate it and format if needed.

http://baby.rustyequipment.com/pages/blog.html

so i could write a file formatted like each of those blocks, but i would just load the page for it to 'read' the file

0

Yeah, then you can do what the guy below said - echo a .txt file in a php page. Just set up a template php file with like the html, head, body and all that - kind of a skeleton, then you could read a directory of .txt files using glob from the server, loop through them to extract the contents of each, and spit the contents out into divs with a css class assigned. If you want titles, you can assume the very first line in the file is the title, then two newlines down or something assume the rest is your content.

0
0

This is called content management, you need a CMS..

0

ill look into that. something i can make myself?

0

just use wordpress like everyone else

0

Pass

0

well, you are looking for something like https://www.staticgen.com/jekyll

which is not php, but flat file based as you request.