mike12255 Posted July 20, 2009 Share Posted July 20, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 $info = "\$dbuser = '$dbuser';"; Quote Link to comment Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 So that you understand what is going on.. echo $variable; // no quotes: $variable is parsed. Value is echoed echo "$variable"; // double quotes: $variable is parsed. Value is echoed echo '$variable'; // single quotes: $variable is not parsed. Literal $variable output. Quote Link to comment Share on other sites More sharing options...
mike12255 Posted July 20, 2009 Author Share Posted July 20, 2009 i did echo " '$dbuser' = $dbuser"; output 'dffdd' = dffdd Quote Link to comment Share on other sites More sharing options...
mike12255 Posted July 20, 2009 Author Share Posted July 20, 2009 rhodesa your way worked, thanks Quote Link to comment Share on other sites More sharing options...
.josh Posted July 20, 2009 Share Posted July 20, 2009 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... Quote Link to comment Share on other sites More sharing options...
mike12255 Posted July 20, 2009 Author Share Posted July 20, 2009 oh, now i understand, thanks for that little lesson Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.