Klaes4Zaugen Klaes4Zaugen - 1 year ago 69
PHP Question

PHP adding $ signs into strings without it being a variable?

I'm making a setup page where people can write their database login etc and that will then create a config.php file on their webserver with the info but obviously I can't just write

$file = fopen("config.php", "w");
fwrite($file, "$dbName = $dbName");

I actually tried

$file = fopen("config.php", "w");
fwrite($file, "$" . "dbName = $dbName");

But that doesn't work either.

Any way to store it as a PHP variable in a file I write using PHP?

Answer Source

As PHP Document says

If the string is enclosed in double-quotes ("), PHP will interpret the following escape sequences for special characters: \$ Dollar Sign


So if you want to use $ in a double-quotes strings use \$ instead of $.

Or simply use single quotes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download