> I have a text file with a series of project variables. > > For example > $var1="xxxx"; > $var2="aaaa"; > $template="blue"; > $anothervar="foo"; > > Let say I need to change $template="blue"; to $template="red";. How can I > do > that keeping the rest of the file intact?
You have to write the whole file over. So read the entire file into a string. If you know you're looking to match $template, then you can use a preg_replace() call. $new_value = "red"; preg_replace('/\$template="[^"]";/','$template="'.$new_value.'";',$text) ; or something similar. Adapt to your needs. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php