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

Get text in another text file

Comments in 'Plugin Development' started by MyNameIsTriXz, Dec 27, 2015.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    What am I doing wrong? I want to get the text from the txt file of another plugin, when I want to execute something on it, it says it is null, but why?

    PHP:
    @mkdir("/storage/emulated/0/PocketMine/plugins/VIP/"0777true);
       
    $this->vips = new Config("/storage/emulated/PocketMine/plugins/VIP/" ."VIPS.txt"Config::ENUM, array());
  2. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    To write text files, you do not use Config().
    Instead, use
    PHP:
    $handle fopen("the/directory/to/file.txt""a");
    and then, to write,
    PHP:
    fwrite($handle$data); // $data is the text information.
    fclose($handle);
    If you want to get data from a text file, do file_get_contents().

    Also, what is that useless '.' doing there? Combine the two strings..
    Last edited: Dec 27, 2015
    MyNameIsTriXz and applqpak like this.
  3. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Couldn't you also use file_put_contents();? And another way is file(); ;)
    MyNameIsTriXz and HotFireyDeath like this.
  4. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    BTW, Opening it in w+ mode will overwrite all exisiting data with the new data being added, Use fopen("the/directory/to/file.txt", 'a'); to append new data to the file, just a heads up. And if you use the file_put_contents("the/directory/to/file.txt", $data); it will overwrite the existing data. So use the FILE_APPEND flag like so: file_put_contents("the/directory/to/file.txt", $data, FILE_APPEND);
    MyNameIsTriXz and HotFireyDeath like this.
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Thanks to everyone, but I already found it out by myself, for these, who are interested:

    PHP:
        $file fopen("/storage/emulated/0/PocketMine/plugins/VIP/VIPS.txt" "r");
                        
    $i 0;
                        while (!
    feof($file)) {
                            
    $vips[] = fgets($file);
                        }
                        
    fclose($file);

    foreach(
    $vips as $vip){     
    if(
    $vip == $sender->getName()){ 
    $sender->sendMessage("§aYou got the §6VIP §bkit§a.");

    $sender->getInventory()->addItem(new Item(26504)); 
    $sender->getInventory()->addItem(new Item(26901)); 
    $sender->getInventory()->addItem(new Item(26504)); 
    $sender->getInventory()->addItem(new Item(35401)); 
    $sender->getInventory()->addItem(new Item(32201)); 
    }}     
    My last question, how am I able to add text there on without deleting the current one?
  6. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Did you not read my earlier posts? :p
    MyNameIsTriXz likes this.
  7. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    You're opening it in READ only mode...
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Yeah I know, thanks fpr helping!
  9. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    No worries!
    MyNameIsTriXz likes this.

Share This Page

Advertisement