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

Edit text in a file

Comments in 'Plugin Development' started by MyNameIsTriXz, Jan 27, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    How can I edit a special string or line in a file?
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    you can use :

    file_put_contents();

    or

    fopen() / fwrite()

    again, do you need the google link?
    PocketKiller likes this.
  3. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You dont understand the question...
    I mean how I edit a special part or line of a text
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    For a special line:

    PHP:
    $lines file($filepath); // a string array containing the lines in the array
    $lines[2] = "This is line three";
    file_put_contents($filepathimplode(PHP_EOL$lines));


    1. Note that it is highly inefficient to edit a file every time. Better cache the changes and save them on disable (and automatically during runtime in case of crashes where the things won't be saved). Actually, it is best to use a Config that is saved in a class property for this purpose.
    2. This is PocketMine Forums, Plugin Development Forum, not PHP forum. If you are asking about PHP API, please go on other sites like stackoverflow.com. You are asking purely "how to do something in PHP" questions.
    Vaivez66 likes this.

Share This Page

Advertisement