Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace a line in a file with php

Status
Not open for further replies.

wazilian1

Programmer
Nov 8, 2002
38
US
anyone ever replace just one line in a file with php. i haven't seen anything out there or any built-in functions that could do this. what i'm looking for is something that replaces a line with another. thats it. something like replace_line(current line, new line); you give it the line string you want to replace and also the line string you wish to add in its place. i imagine i will have to write my own or just overwrite the whole file or something. just a little help if anyone has any ideas. thanx in advance.

wazilian
King of Wazil
 
You're going to have to write your own.

One way to do it is to open the file and write it to a new file, replacing text as necessary. Then close both files, delete the old, and rename the new to the old file's name.

I'd recommend that you employ file-locking ton insure that no other script attempts to change the file at the same time, or even read it.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top