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); ?> Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/ Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 $info = "\$dbuser = '$dbuser';"; Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/#findComment-878907 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. Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/#findComment-878908 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 Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/#findComment-878919 Share on other sites More sharing options...
mike12255 Posted July 20, 2009 Author Share Posted July 20, 2009 rhodesa your way worked, thanks Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/#findComment-878925 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... Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/#findComment-878926 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 Link to comment https://forums.phpfreaks.com/topic/166683-solved-trouble-writting-a-variable-name-to-a-file/#findComment-878955 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.