变量PHP文件读取

变量PHP文件读取,php,Php,我试图让一个php程序打开一个文本文件并读取内容。我需要做的是更改文件名,但保留.txt扩展名 $Task = $_POST['Task']; $Breifing = file_get_contents("T001.txt"); 因此,在上面的示例中,我想根据$Task的内容对T001进行更改 我试过这句话: %Breifing = file_get_contents(%Task,".Txt"); 但这不起作用 任何帮助都将不胜感激。如果有机会,你可

我试图让一个php程序打开一个文本文件并读取内容。我需要做的是更改文件名,但保留.txt扩展名

$Task = $_POST['Task'];

$Breifing = file_get_contents("T001.txt");
因此,在上面的示例中,我想根据$Task的内容对T001进行更改

我试过这句话:

%Breifing = file_get_contents(%Task,".Txt");
但这不起作用

任何帮助都将不胜感激。

如果有机会,你可能会找到一本好书。不过,要回答您的问题,有几种不同的方法:

file_get_contents(sprintf('%s.txt', $Task)) // will probably work
// OR
file_get_contents("{$Task}.txt")
// OR (as mentioned in the comments above)
file_get_contents($Task . '.txt')
// OR since $Task is just a string you could concatenate '.txt' on it and just pass it wholesale
$Task = $Task . '.txt';
file_get_contents($Task);

那么
$Breifing=file\u get\u contents($Task..txt)呢请参阅。