News script in flat file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dalibor

    News script in flat file

    I wrote some code for displaying news on my website.
    Code goes like this:
    <?
    $newsfile = 'news.txt';
    echo "<B>TRENUTN E 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:no rmal 11px
    Tahoma\"><u>Pub lished</u>: " . $pieces[1] . " " . $pieces[0] .
    "</span></span><BR><br>";
    }
    ?>
    I have form that puts content in flat file.

    Messages are writen in flat file in format like this:
    21.Feb 2006.|Dalibor|S ome message text
    14.Feb 2006.|Dalibor|O ther message text...

    I need piece of code for displaying last 5 messages and for deleting
    certain messages.
    Can you help me? Thanks!
    --
    ..:Dalibor:.
  • Michael Austin

    #2
    Re: News script in flat file

    Dalibor wrote:
    [color=blue]
    > I wrote some code for displaying news on my website.
    > Code goes like this:
    > <?
    > $newsfile = 'news.txt';
    > echo "<B>TRENUTN E 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:no rmal 11px
    > Tahoma\"><u>Pub lished</u>: " . $pieces[1] . " " . $pieces[0] .
    > "</span></span><BR><br>";
    > }
    > ?>
    > I have form that puts content in flat file.
    >
    > Messages are writen in flat file in format like this:
    > 21.Feb 2006.|Dalibor|S ome message text
    > 14.Feb 2006.|Dalibor|O ther message text...
    >
    > I need piece of code for displaying last 5 messages and for deleting
    > certain messages.
    > Can you help me? Thanks![/color]

    writing your own newsreader?

    have you looked at http://www.newsportal.one.pl

    It even runs on my OpenVMS/Alpha system.

    --
    Michael Austin.
    DBA Consultant
    Donations welcomed. Http://www.firstdbasource.com/donations.html
    :)

    Comment

    • samudasu

      #3
      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.

      Comment

      • Dalibor

        #4
        Re: News script in flat file

        On 17 Feb 2006 20:01:51 -0800, samudasu wrote:
        [color=blue]
        > 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.[/color]

        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
        message.
        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.
        --
        ..:Dalibor:.

        Comment

        • samudasu

          #5
          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_conten ts.

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

          delnews.php.... .........
          <?php
          $file = 'news.txt';
          $data = file($file);
          unset($data[$_GET['del']]);
          print "<pre>";
          print_r($data);
          print "</pre>";
          file_put_conten ts($file, $data);
          ?>

          Comment

          • Dalibor

            #6
            Re: News script in flat file

            I did it! Thanks everybody for hellping me!
            --
            ..:Dalibor:.

            Comment

            Working...