Hi everyone, I have a slight problem that I hope you can help me with.

I am trying to write a website to display the poems and songs my grandfather wrote beore passing away.

Seeing as most of his work was poems the formatting is important!

Ideally what I would like would be to place each poem in a seperate text file and then using php call the file and display the contents with its original formatting.

If its not possible to do in php I wouldn't be adverse to using another language.

Any help would be greatly appreciated.

Regards,

Darragh

Dani AI

Generated

Nice, keeping each poem in its own plain text file is a solid, low-friction approach. As pointed out and confirmed, reading the file and rendering it with preserved spacing works well. A few practical tips to make that result look right and stay safe over time.

Treat the file contents as plain text and escape any HTML before sending it to the browser to prevent embedded markup from running. If you want browser-handled linebreaks but still allow responsive wrapping, use the CSS white-space value pre-wrap (see MDN white-space). Alternatively, convert newlines to breaks server-side while escaping first; the PHP functions for escaping and newline conversion are documented at htmlspecialchars and nl2br.

Security and maintenance notes: never use unchecked user input as a filename (whitelist or map safe slugs to files), store editable files outside the webroot if possible, and set conservative file permissions. Save poem files in UTF-8 (without a BOM) to avoid character issues. If you plan search, tagging, or versioning, keep a small metadata store (JSON or a simple database) rather than encoding metadata into filenames.

Recommended Answers

All 2 Replies

You can just use file_get_contents to, well, get the contents of the file then when you output it just wrap it in a <pre> tag to keep the original formatting.

Looks like I am an idiot! Works just right thank you!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.