How do I fwrite without removing previous data? Heres my code: PHP: public function onCommand(CommandSender $sender, Command $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; } } } }}
You could also change from write mode to append mode in fopen(). Like: PHP: $file = fopen($this->getDataFolder() . "arenas/"."arenas.txt", "a");
sorry to ask but how do I use \n properly, the list comes out as "Test1Test2" I want it as: "Test1 Test2"
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.
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);