PHP 在不作为变量的情况下将 $ 符号添加到字符串中?

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

我正在制作一个设置页面,人们可以在其中写入他们的数据库登录信息等,然后会在他们的网络服务器上创建一个包含信息的 config.php 文件,但显然我不能只写

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

我真的试过了

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

但这也不管用。

有什么方法可以将它作为 PHP 变量存储在我使用 PHP 编写的文件中?

如PHP 文档所述

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

因此,如果您想在双引号字符串中使用 $,请使用 $ 而不是 $

或者直接使用单引号