0

我到处寻找一种简单的方法来做到这一点,但无法正确。在 php 中,我想为变量分配一个名称,然后用变量替换字符串中的名称。斜杠导致语法错误。

//Assign the name to a variable.
$patient_name = "John_Doe";

//Replace the name in this string with the variable.
header("Content-Disposition: attachment; filename=\"John_Doe.pdf\"");
4

2 回答 2

1

只需使用其中的变量即可。像这样

<?php
$patient_name = "John_Doe.pdf";
header("Content-Disposition: attachment; filename=$patient_name");
                                          --------^
于 2013-11-14T06:02:58.740 回答
1

在双引号内,您可以使用大括号来封装变量,如下所示:

header("Content-Disposition: attachment; filename='{$patient_name}.pdf'");
于 2013-11-14T06:03:29.453 回答