[PHP] Re: Writing to a file

2009-07-03 Thread Shawn McKenzie
Jason Carson wrote:
> Hello everybody,
> 
> How would I go about writing stuff to a file but in between the 
> tags?
> 
> Example, say I have config.php as follows...
> 
>  
> $hostname = "localhost";
> $database = "database";
> $username = "username";
> $password = "password";
> 
> ?>
> 
> How would I go about adding stuff at the end of the file, but before the
> ?> tag?
> 

The way I've done this in the past is to use an array.  Then I can
include the file, change the array and then var_export() to the file:

//config.php
 'localhost',
  'database' => 'database',
  'username' => 'username',
  'password' => 'password',
);


//file that does the changing writing
";
file_put_contents('config.php', $content);

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: writing to a file

2002-03-07 Thread David Robley

In article <[EMAIL PROTECTED]>, vallee.marc-
[EMAIL PROTECTED] says...
> Hi,
> 
> Here is a foo.txt file :
> 
> name=foo
> age=100
> sex=y
> 
> I want to open the file, find the age line, and then replace the 100 with
> another value.
> The only way i see, is to rewrite the entire file

That is correct. You need to load the file into your script, make 
whatever changes and then write it back.
> 
> Maybe this is a stupid question, but, i tried the online doc, and saw
> nothing about this
> 

-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php