Jump to content

Syntax Help


ShoeLace1291

Recommended Posts

I'm trying to make a form that edits a php file which contains config settings.  I'm using strings that are defined by the user form inputs.  This is what my file should look like when the form is process(or something like it)

 

<?php

$config['site_url'] = "http://localhost/sideeffect";

$config['site_name'] = "asdfasdf";
$config['site_motto'] = "A community of gamers";
$config['img_dir'] = $config['site_url']."/images";
$config['style_dir'] = $config['site_url']."/css";
$config['js_dir'] = $config['site_url']."/javascript";
$config['enable_comments'] = FALSE;
$config['enable_points'] = TRUE;	
$config['enable_ratings'] = FALSE;
$config['maintenance_mode'] = TRUE;			

?>

 

This is the bit that produces what should be written to the file:

$data = "<?php\n\n

			$config[\'site_name\'] = \"".$info['site_name']."\";\n  [b]//Line that the error occurs on[/b]
			$config[\'site_motto\'] = \"".$info["site_motto"]."\";\n
			$config[\'img_dir\'] = \"".$info["img_dir"]."\";\n
			$config[\'style_dir\'] = \"".$info["style_dir"]."\";\n
			$config[\'js_dir\'] = \"".$info["js_dir"]."\";\n
			$config[\'enable_comments\'] = \"".$comments."\";\n
			$config[\'enable_points\'] = \"".$points."\";\n
			$config[\'enable_ratings\'] = \"".$ratings."\";\n
			$config[\'maintenance_mode\'] = \"".$maintenance."\";\n\n

			?>";

 

This is the error that I'm getting:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\sideeffect\system\application\models\admin\settings.php on line 4

 

Thanks for your help.

Link to comment
Share on other sites

$data = "<?php\n\n";

foreach($info as $name => $value)
{
    $data .= "\$config['{$name}'] = \"{$value}\";\n";
}
$data .= "\$config['enable_comments'] = {$comments};\n";
$data .= "\$config['enable_points'] = {$points};\n";
$data .= "\$config['enable_ratings'] = {$ratings};\n";
$data .= "\$config['maintenance_mode'] = {$maintenance};\n";

$data .= "\n\n?>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.