file_put_contents不使用$ variables?

时间:2016-02-02 10:14:47

标签: php

你好:)我有一个关于PHP的file_put_contents的问题。我有一个注册用户的功能,每次有人注册时,它会为每个用户创建一个PHP脚本。

file_put_contents('handlers/get_trades_$email.php',"a tonne of code");

正如您在上面所看到的那样,创建文件的脚本就是创建的,但它实际上是为文件名称“get_trades_ $ email.php”,而不是所需的(示例)“get_trades_willsmith @bling”。 com.php“

关于如何解决这个问题的任何建议我将非常感激;)

干杯, 约书亚

1 个答案:

答案 0 :(得分:2)

单引号不解析内部变量。所以你应该做以下任何一种:

file_put_contents('handlers/get_trades_' . $email . '.php',"a tonne of code");

file_put_contents("handlers/get_trades_$email.php","a tonne of code");

file_put_contents(sprintf("handlers/get_trades_%s.php", $email),"a tonne of code");