Page 1 of 1

[solved] writing to a config file

Posted: Mon May 29, 2006 8:21 am
by andym01480
I'm working on a setup.php script to write a config.inc.php file after the user inputs data and the data is validated.
I'm writing $somecontent to the file. $somecontent is at the moment made up of

Code: Select all

$somecontent = '<?php  $adminpassword=';
$somecontent .=$adminpassword;
$somecontent .=';\n $moderate=';
$somecontent .=$moderate;
$somecontent .=';\n $postsperpage=';
$somecontent .=$postsperpage;
$somecontent .='; ?> ';
When, its finished the config.inc.php looks like this

Code: Select all

<?php  $adminpassword=3bad6af0fa4b8b330d162e19938ee981;\n $moderate=y;\n $postsperpage=1; ?>
which when used creates this error

Code: Select all

Parse error: syntax error, unexpected T_STRING in /home/amoyle/public_html/guestbook/config.inc.php on line 1
I've tried various options of tryin to get newlines written to the file \n, \r\n etc, but no luck on my Xxamp windows installation or a linux server.

What have I done wrong?

Posted: Mon May 29, 2006 10:21 am
by Ambush Commander
Single quotes don't allow you to create newlines. You need "\n" (double-quotes)

SOLVED: Writing to config file

Posted: Mon May 29, 2006 10:51 am
by andym01480
I don't believe it! Of course, I used the single quotes to have the variable names, knowing they wouldn't be parsed and forgot it wouldn't parse newlines. Doh! :oops: