PHP File reading question. Again :/

Discussion in 'PHP' started by deviant, Aug 9, 2008.

  1. #1
    I have a groups.txt file with some text datas on it.

    Datas are listed in the text as;

    Nockin:JJKEL
    Nursan:OLZK
    Besat:JKANW
    Sucan:QQOW

    I want to write first data (by reading groups.txt) to php page then remove it from the list.

    So first visitor will see the:

    Nockin:JJKEL

    Second visitor will see the:

    Nursan:OLZK

    Third visitor will see the

    Besat:JKANW

    And so on!

    I can also pay for this. Upon request.
     
    deviant, Aug 9, 2008 IP
  2. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Try this:

    
    <?php
    
    $myFile = "groups.txt";
    $fh = fopen($myFile, 'w+');
    
    echo "Group $fh";
    
    ?>
    
    PHP:
     
    jpinheiro, Aug 9, 2008 IP
  3. deviant

    deviant Peon

    Messages:
    58
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not worked :/
     
    deviant, Aug 9, 2008 IP
  4. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use this, it'll display the string on the first line, then that on the second line, etc, as each successive visitor visits it. It should work, or at least it does for me...

    <?php
    
    $fileName = 'groups.txt';
    
    chmod($fileName, 0777);
    
    $fileArray = file($fileName);
    
    echo $fileArray[0];
    
    unset($fileArray[0]);
    
    file_put_contents($fileName, $fileArray);
    
    ?>
    PHP:
    Please note that this above physically deletes each line from the text file as it is displayed. If you want this not to happen, use this code below and give people links like FILENAME-HERE.php?id=ID-NUMBER-HERE, where ID-NUMBER-HERE is the line number in the text file and FILENAME-HERE is (of course) the filename of this php code below.

    <?php
    
    $userID = intval($_GET['id']) - 1;
    
    $fileName = 'groups.txt';
    
    $fileArray = file($fileName);
    
    echo $fileArray[$userID];
    
    ?>
    PHP:
    No thanks, just +rep if I've helped :)
     
    Pos1tron, Aug 9, 2008 IP
    deviant likes this.
  5. deviant

    deviant Peon

    Messages:
    58
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Pos1tron. It's worked and I'm using your way. Thank you very very much.
     
    deviant, Aug 9, 2008 IP