Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

fwrite() help!

Comments in 'Plugin Development' started by iiDeathStrokeii, Jun 22, 2015.

  1. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    How do I fwrite without removing previous data?
    Heres my code:
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
    switch(
    $command->getName()){
    case 
    "ss":
        if(isset(
    $args[0]) && isset($args[1] && isset($args[2])){
                switch(
    $args[0]){
                     case 
    'create':
                         switch(
    $args[1]){
                            case 
    'arena':
                                   
    $sender->sendMessage("TEST");
                                   
    $file fopen($this->getDataFolder() . "arenas/"."arenas.txt""w");
                                   
    fwrite($file$args[2]."\n");
                                   
    fclose($file);
                                   return 
    true;
                                   break;
                        }
                }
        }
                  
    }
    }
  2. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
  3. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Thanks
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    You could also change from write mode to append mode in fopen().

    Like:

    PHP:
    $file fopen($this->getDataFolder() . "arenas/"."arenas.txt""a");
    EvolSoft and iiDeathStrokeii like this.
  5. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    sorry to ask but how do I use \n properly, the list comes out as "Test1Test2"
    I want it as:
    "Test1
    Test2"
  6. Intyre
    Offline

    Intyre Staff Member PocketMine Team

    Joined:
    Aug 24, 2013
    Posts:
    118
    Minecraft User:
    Intyre
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    WHAT THE
    What is the point of everything if you are going to read all contents and save it in memory and write it to the disk again, THEN append the real data? The first processes (read and write) are totally meaningless.
    EvolSoft and Falk like this.
  8. Wuros
    Offline

    Wuros New Member

    Joined:
    Sep 12, 2014
    Posts:
    8
    Minecraft User:
    Wuros
    You sholud use "r+"
    It allow to write and read
    Use:
    PHP:
    $file fopen($this->getDataFolder() . "arenas/"."arenas.txt""r+");
    fwrite($file$args[2]."\n");
    fclose($file);
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The problem is, you don't need to read at all...

Share This Page

Advertisement