[solved] writing to a config file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

[solved] writing to a config file

Post 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?
Last edited by andym01480 on Mon May 29, 2006 3:28 pm, edited 1 time in total.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Single quotes don't allow you to create newlines. You need "\n" (double-quotes)
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

SOLVED: Writing to config file

Post 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:
Post Reply