+ Reply to Thread
Results 1 to 4 of 4

Thread: PHP bulletin-type-thing

  1. #1
    ethicalkidnap is offline x10Hosting Member ethicalkidnap is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    2

    PHP bulletin-type-thing

    Hey guys, I'm new here, as you can probably tell.
    I have a little problem with a certain PHP script.

    I'm trying to create a bulletin type system where an admin can enter a message into the given text area and it appears on the front page, but only using text files and the fopen() and fwrite() functions.

    The problem I'm having is that I need the newest posts to appear above the older posts, I've done it before but have completely forgotten how I did it xD

    So far I have:

    PHP Code:
    <?php
    $date 
    date("D M j G:i:s");
    $file 'body.txt';
    $inf "<b>".$date."</b><br />".stripslashes($_POST['index'])."<br /><br />";

    !
    $handle fopen($file'a');
    fwrite ($handle$inf);
    echo 
    "Success, wrote text to <a href='index.php'>index</a>";
    fclose($handle);
    ?>
    I know the fopen() mode is wrong, and that's part of the problem >.>

    I also know I need the pointer to back to the top of the document, and I've tried rewind() and fseek(), but they haven't worked

    Does anyone have an idea of how I would go about acheiving what I want to do?
    Last edited by ethicalkidnap; 10-06-2007 at 05:40 PM.

  2. #2
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: PHP bulletin-type-thing

    Right, I'd better get some rep for this :P

    To get the pointer to the start of the document, you would use
    PHP Code:
    fseek($handle0); 
    I'd use a+ instead of a cause if the file doesn't exist, it'll create it. 'a' puts the file pointer at the very end of the file which is good if you are appending data.

    Now to get the part you were asking about, displaying the news in reverse order. This is really easy if you store each news item on a single line.

    PHP Code:
    <?php
    $data 
    file('body.txt');
    $data array_reverse($data);
    foreach(
    $data as $element) {
        
    $element trim($element);
        echo 
    $element;  //Do whatever fancy formatting you want to do here.
    }
    ?>
    A preferable approach would be to serialize an array containing your news posts and store THAT in the flatfile instead. Lemme know if you'd like to know bout that and perhaps I'll post up a quick tutorial.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  3. #3
    ethicalkidnap is offline x10Hosting Member ethicalkidnap is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    2

    Re: PHP bulletin-type-thing

    Aww man, that's exactly what I was looking for!
    Thanks a lot!! =D
    Enjoy your slightly higher reputation ;D

  4. #4
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: PHP bulletin-type-thing

    Haha.. np.. Glad to be of assistance :P

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers