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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using PHP to EDIT a file?

Status
Not open for further replies.

djtizzlemaster

Programmer
Mar 5, 2008
17
US
I'm getting pretty familiar with PHP fopen, fwrite, and fclose functions, which you can use to create, open, write to, and append to files. But I still havent figured out how to - or if you can - EDIT a file.

Let's say we've got this:

Code:
Line 1
Line 2
Line 3

Now, what I want to do is change "Line 1" to "Line A."

Is there a simple way to do that, which doesn't require me to include everything that comes after Line A (such as "Line A\nLine 2\nLine 3")?
 
You need to get the entire file into probably an array, edit the line that contains what you wan to edit and then write it all back.

Perhaps the file() function can help you do it. Click on the function name for the PHP manual entry for it.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top