Page 1 of 1

Add/Replace Line/Text in TextFiles

Posted: Fri Mar 26, 2004 3:39 am
by magOO
Hello!
I need for my project a Function that Add or Replace Textstrings or a whole Line in a Textfile like the ModInstaller for phpBB.
It should able to do the following actions:
  • Add a Line Before another Line
    Add a Line After another Line
    Replace a Line
    Write String After a String in Line
    Write String Before a String in Line
    Replace String in Line
Is there a function out or how can i write a function that can do it?
Thanks for your help
magOO

Sorry for my bad English :oops:

Re: Add/Replace Line/Text in TextFiles

Posted: Fri Mar 26, 2004 8:17 am
by TheBentinel.com
You could split the text file into an array of lines, then you could do whatever you wanted with it.

Look into the split() and explode() functions.

http://php.net/split
http://php.net/explode

You'll split on the newline character ("\n") or perhaps on "\r\n", depending on your file. Try "\n" and if you get what you want you're in good shape.