如何在不连接的情况下将值插入字符串


How can I insert a value into a string without concatenation?

我的目标是将变量的值直接插入字符串中,而无需使用 . 运算符进行连接。

我试过这样:

$filename = 'some_file_name';
header('Content-disposition: attachment; filename=$filename');

但这给了我filename=$filename,而不是filename=some_file_name

我如何实现这一点?我错过了什么?

$filename = "path/to/file.txt";
header("Content-disposition: attachment; filename=$filename");
$filename = 'test.txt';
header('Content-disposition: attachment; filename=' . $filename);

试试这个:

header('Content-Disposition: attachment; filename="' . $document . '"');

其中$document是你的变量。此处添加了双引号,因此您可以在其中添加空格您的文件名。