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

喜欢而已 提交于 2019-12-25 18:32:16

问题


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?


回答1:


As PHP Document says

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

http://php.net/manual/en/language.types.string.php

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

Or simply use single quotes



来源:https://stackoverflow.com/questions/39109245/php-adding-signs-into-strings-without-it-being-a-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!