Re: replacing a line in a file
| From: | Aviv Revach | Date: | Mon, 12 Mar 2001 23:45:58 +0000 |
| Subject: | Re: replacing a line in a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-43732@lists.php.net to get a copy of this message | ||
Hey!
I didn't try to analyze your code, but why not using the file() function
which opens a file and puts it's content into an array.
After doing that, you could seek that array line-by-line for "$data[0]:$shadow[1]"
and replace it with $data[0]:$data[1].
Since you're dealing with full lines in your script, file() is the best choice (though,
sometimes not the fastest).
It will also improve your code by making it much easier to read than when using
fopen(), fread(), etc.. as you're doing now.
Best Regards -
Aviv Revach
At 17:29 13/03/01 -0600, enthalpy wrote:
having problems replacing a line in a file. need to search the whole document for a string and then replace that line with a string. any ideas? this is causing lots of problems now. $fpoint3 = fopen ($testshadow, "r+") or die("couldnt open shadow file again"); $contents = fread ($fpoint3, $shadowfilesize); fputs ($fpoint3, ereg_replace("$data[0]:$shadow[1]", "$data[0]:$data[1]", $contents)); fclose ($fpoint3); any ideas? <-----CoreComm-Internet-Services---http://core.com----->XOR-Coders Mega Programming Resource Site! -(Jon Marshall CoreComm Services Chicago) (jonathon.marshall@core.com Systems Engineer II) (enthalpy@core.com Network Operations)<-----Enthalpy.org-------------http://enthalpy.org----->(enthalpy@enthalpy.org The World of Nothing)<------------------------------------------------------> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
http://members.xoom.com/xorcoders/