Page 1 of 1

Edit textfile line

Posted: Mon Nov 22, 2010 5:32 am
by skallagrimur
Hello, I'm looking for help with editing a text file.

Here is a sample of the text file:
[text]variable_1|variable_2|variable_3|variable_4
variable_1|variable_2|variable_3|variable_4
variable_1|variable_2|variable_3|variable_4[/text]
I need to be able to edit variable_3 in each line that variable_3 is null.

Hopefully I'm making myself clear enough. All help very much appreciated.

Thank you, skallagrimur

Re: Edit textfile line

Posted: Mon Nov 22, 2010 6:26 am
by Celauran
Use a multidimensional array. Read the file into the array line by line, explode the lines on |, loop through the array making changes as needed, implode using | to get the initial formatting back, write to file.

Re: Edit textfile line

Posted: Mon Nov 22, 2010 6:46 am
by skallagrimur
I'll try that. Thanks..