SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Advice on this code

    PHP Code:
    <?php

    class Shoutbox {
       var 
    $fso;                 /* For the file I/O */
       
    var $strsep "~";        /* To seperate the data in the file */
       
    var $sboxfile "sbox.db" /* File to hold the shouts */;
       
          function 
    add($date$name$shout) {
          
    $date trim($date);
          
    $name trim($name);
          
    $shout trim($name);
          
    # +a = Read/Write !exist(create) EOF
          
    if ($this->fso fopen($this->sboxfile"a+")) {
             if (
    is_writeable($this->sboxfile)) {
                
    #If it wrote correctly, close and return true
                
    if (fwrite($this->fso$date $this->strsep $name $this->strsep $shout"\n")) {
                   
    fclose($this->fso);
                   return 
    true;
                }
             }
          }
          return 
    false;
       }

       function 
    display($reverse "true") {
          
    $shouts = array();
          
          if (
    is_readable($this->sboxfile)) {
             
    $fso file($this->sboxfile);

             if (
    $reverse) {
                
    arsort($fso);
             }
             foreach(
    $fso as $line) {
                list(
    $date$name$shout) = explode($this->strsep$line);
                
    $shouts["dates"][] = $date;
                
    $shouts["names"][] = $name;
                
    $shouts["shouts"][] = $shout;
             }
             return 
    $shouts;
          }
          return 
    false;
       }
       
    }

    ?>
    Just a small shoutbox backend i wrote, i would be grateful for any comments. thanks

  2. #2
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *bump*

  3. #3
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Dangermouse, please don't 'bump' your threads in the SitePoint forums.

    By the way, your code looks good. Did you have any specific questions about it or did you just want us to review it?

    If you just wanted a review, perhaps you should look into the Reviews and Critiques forum in the "Site Elements" section.
    http://www.sitepoint.com/forums/forumdisplay.php?f=90
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •