Edit textfile line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skallagrimur
Forum Newbie
Posts: 9
Joined: Fri Nov 12, 2010 4:33 am

Edit textfile line

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Edit textfile line

Post 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.
skallagrimur
Forum Newbie
Posts: 9
Joined: Fri Nov 12, 2010 4:33 am

Re: Edit textfile line

Post by skallagrimur »

I'll try that. Thanks..
Post Reply