News script in flat file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I wrote some code for displaying news on my website.
Code goes like this:
$newsfile = 'news.txt';
echo "<B>TRENUTNE VIJESTI</B><br>\n";
$data = file($newsfile);
$data = array_reverse($data);
echo "<span style=\"normal 11 Verdana; color:#fff; text-align:justify;\">";
foreach($data as $element) {
    $element = trim($element);
    $pieces = explode("|", $element);
    echo $pieces[2] . "<BR>" . "<span style=\"font:normal 11px
Tahoma\"><u>Published</u>: " . $pieces[1] . " " . $pieces[0] .
I have form that puts content in flat file.

Messages are writen in flat file in format like this:
21.Feb 2006.|Dalibor|Some message text
14.Feb 2006.|Dalibor|Other message text...

I need piece of code for displaying last 5 messages and for deleting
certain messages.
Can you help me? Thanks!

Re: News script in flat file

Dalibor wrote:

Quoted text here. Click to load it

writing your own newsreader?

have you looked at

It even runs on my OpenVMS/Alpha system.

Michael Austin.
DBA Consultant
Donations welcomed. Http://

Re: News script in flat file

Use array_slice to extract the last five messages. What constitutes a
"certain" message? Little hard to provide an example when we dont' know
what "certain" equals.

Re: News script in flat file

On 17 Feb 2006 20:01:51 -0800, samudasu wrote:

Quoted text here. Click to load it

Well I ment to have admin page for news, in which will be diplayed all
messages, and after each message i want to be link for deleting that
Like this:
Some message text
By Dalibor on 21.Feb 2006. - Delete
Other message text...
By Dalibor on 14.Feb 2006. - Delete

And when I press delete message is deleted.

Re: News script in flat file

This code will delete your messages. It's coded for php5. If you're
running php4 then you'll have to substitute fopen, fwrite, and fclose
for file_put_contents.

$data = file('news.txt');
foreach ($data as $key => $value) {
    print "$value: <a href=\"delnews.php?del=$key\">delete</a><br

$file = 'news.txt';
$data = file($file);
print "<pre>";
print "</pre>";
file_put_contents($file, $data);

Re: News script in flat file

I did it! Thanks everybody for hellping me!

Site Timeline