Just wondering is this possible? I am trying to do a mini announcement section in my website. What i want is for the announcement to be taken from a txt file for easy updating.
Regards,
Jon
Just wondering is this possible? I am trying to do a mini announcement section in my website. What i want is for the announcement to be taken from a txt file for easy updating.
Regards,
Jon
As asked about keeping announcements in a .txt for easy updates and touched on the limitations of static pages, here are practical, current ways to do it and the important caveats.
Server-side (recommended): have the server read the file and inject it into the page. Example (place in a .php page):
<?php
// output safely: escape any HTML and preserve newlines
echo nl2br(htmlspecialchars(file_get_contents(__DIR__ . '/announcements.txt')));
?> Client-side (if you cannot run server code): fetch the text over HTTP and insert it as plain text to avoid XSS:
fetch('/announcements.txt')
.then(r => r.ok ? r.text() : Promise.reject(r.statusText))
.then(t => document.getElementById('announcements').textContent = t)
.catch(e => console.error('Announcement load failed:', e)); Notes and troubleshooting:
textContent or escape output on the server (htmlspecialchars) to prevent script injection.Jump to Post— Arkinder 93This is not possible with HTML or CSS. You would need a server-side language like PHP.
Regards
Arkinder
This is not possible with HTML or CSS. You would need a server-side language like PHP.
Regards
Arkinder
Thanks for the info.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.