Jump to content

[SOLVED] trouble writting a variable name to a file


mike12255

Recommended Posts

so im trying to "create" a config file based on a users entered data so i setup myself kind of a test

 

I want write this to the file:

 

$dbuser = dffdd;

 

instead im getting this:

 

dffdd = dffdd

 

can anyone help me change the first dffdd to the variable name $dbuser?

 

 

<?php

$fn = "config.php";

$fh = fopen($fn ,'w') or die("can't open file");
chmod($fn,0777);
$dbuser = "dffdd";

$info = "".$dbuser." = $dbuser";
fwrite($fh, $info);
fclose($fn);


?>

 

Link to comment
Share on other sites

Your situation involves assigning it to a variable.  echo was just an example to portray how php parses things. The reason

 

echo " '$dbuser' = $dbuser";

 

did not work is because you are still wrapping it in double quotes, overall.  so that would output

 

'value' = value

 

So the idea is to get the first $dbuser to be interpreted literally, while the 2nd one should be parsed.  So you can escape the dollar sign as rhodesa did, or any other combo such as

 

$info = '$dbuser' . " = '$dbuser'";
$info = '$dbuser' . " = '" . $dbuser . "'";
// etc...

 

 

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.