www.webdeveloper.com
Results 1 to 3 of 3

Thread: text file managment help

  1. #1
    Join Date
    Aug 2005
    Posts
    76

    text file managment help

    Ok I am working on making a auto delete function for a shoutbox script that uses a text file for the database. The function should delete any data that is greater than a set number. This is what I have now.

    PHP Code:
    function deleteOld() {
        global 
    $entriesFile;
            
    $limit "10"// Any key greater than 10 will be deleted
            
    $shout file ($entriesFile);
        while (list (
    $key$val) = each ($shout)) { 
                if (
    $key >= $limit) {
                    list(
    $id$time$shoutbox_name$shoutbox_msg$shoutbox_url$shoutbox_ip) = explode("|",$val); 
                    
    $fp fopen($entriesFile"r");
                    
    $data fread($fpfilesize($entriesFile));
                    
    fclose($fp);

                    
    $old "$id|$time|$shoutbox_name|$shoutbox_msg|$shoutbox_url|$shoutbox_ip|";
                    
    $new "";

                    
    $data str_replace($old$new$data);
                        
                    
    $fp fopen($entriesFile"w");
                    
    fputs($fp$data);
                    
    fclose($fp);
                }
        }

    This seems to work fine for a bit, but then starts to slowly remove parts of the last $key.

    example of the text file:
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|

    What starts to happen:
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_

    Then:
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shoutbox_ip|
    id|time|shoutbox_name|shoutbox_msg|shoutbox_url|shou

    I can't figure out why it is removing sections of the last $key like that. It seems to be random also, does it sometimes doesn't do it other times. Has anybody had a problem like this before? Or have any ideas of whats going on? Thanks.

  2. #2
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    wouldnt a mySQL database be a whole lot easier?

  3. #3
    Join Date
    Aug 2005
    Posts
    76
    Yes but this shoutbox is using ajax to update the shouts without page refreshs. So the users can chat basically like a chat room. My host has a note about not using chat scripts on there mysql for extreme loads, so I would like to keep it on a text file.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles