Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将值传递给php文件以更改文件中的文本,然后强制下载相同的文件_Php - Fatal编程技术网

将值传递给php文件以更改文件中的文本,然后强制下载相同的文件

将值传递给php文件以更改文件中的文本,然后强制下载相同的文件,php,Php,下载链接: <a href="download.php?words=2000&sort=popular&type=xml">Download php file</a> 这是强制下载的代码。但我不知道如何用$content=“”;)包装整个页面;。我知道如何包装HTML代码,但是如何包装页面上的PHP函数和代码 header("Content-Disposition: attachment; filename="download.php"); print

下载链接:

<a href="download.php?words=2000&sort=popular&type=xml">Download php file</a>
这是强制下载的代码。但我不知道如何用$content=“”;)包装整个页面;。我知道如何包装HTML代码,但是如何包装页面上的PHP函数和代码

header("Content-Disposition: attachment; filename="download.php");
print $content;

不确定这是否是你想要的;但是,您可以创建第二个脚本来调用第一个脚本,获取输出,并使用提到的头发送该脚本:

<?php
$words = (int) $_GET['words'];
$sort = $_GET['sort'];

$url = sprintf("http://localhost/wherever/download.php?words=%d&sort=%s&type=xml", $words, $sort);
$content = file_get_contents($url);

header("Content-Disposition: attachment; filename="download.php");
print $content;
?>

你能在
中定义
包装吗。。。如何在页面上包装PHP函数和代码
?您好,因为我必须打印$content;获取页面上的特定部分。所以,据我所知是$content=“我想打印的内容。”;。但我不知道如何包装php:$content=“只需转义使其作为php处理的字符即可。例如,当您在HTML文件中显示内容时,您可以从每个
开始,这样您实际上是在尝试向用户提供
download.php
输出的整个源代码?我是否应该关心您的示例中是否有
type=json
,但该文件实际上使用了XML?您不需要包装任何内容。由于文件是作为附件下载的,而不是加载到浏览器中,因此它将按原样保存。如果不想将数据解析为XML,则应使用
file\u get\u contents()
而不是
simplexml\u load\u file()
header("Content-Disposition: attachment; filename="download.php");
print $content;
<?php
$words = (int) $_GET['words'];
$sort = $_GET['sort'];

$url = sprintf("http://localhost/wherever/download.php?words=%d&sort=%s&type=xml", $words, $sort);
$content = file_get_contents($url);

header("Content-Disposition: attachment; filename="download.php");
print $content;
?>