hey guys, I'm a little messed up with reading/writing files. How would you acomplish the task the replace a special line in a given file where the line is something like $name = "bla"; and has to be replaced with another name?
Surely I could read the entire file into a variable use str_replace and then write the whole file back but isn't there a more elegant way??? (i.e. reading line by line and editing just the current line?)
editing files
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you can either do line-by-line, or the entire file in one hit, however, it may change things unexpectedly..
I've used [php_man]file[/php_man]() and [php_man]file_get_contents[/php_man]() to read the files in, and [php_man]fopen[/php_man]/[php_man]fwrite[/php_man]/[php_man]fclose[/php_man] (since I'm not using php5 yet) to drop them out..
I've used [php_man]file[/php_man]() and [php_man]file_get_contents[/php_man]() to read the files in, and [php_man]fopen[/php_man]/[php_man]fwrite[/php_man]/[php_man]fclose[/php_man] (since I'm not using php5 yet) to drop them out..