PHP头将一个PHP文件显示为另一个PHP文件

PHP头将一个PHP文件显示为另一个PHP文件,php,http-headers,Php,Http Headers,是否可以将一个php文件的内容显示给另一个php文件? 我这里有一个例子,在PDF中显示在一个php文件中 <?php $file = 'path of your PDF file'; $filename = 'custom pdf file name'; /* Note: Always use .pdf at the end. */ header('Content-type: application/pdf'); header('Content-Di

是否可以将一个php文件的内容显示给另一个php文件? 我这里有一个例子,在PDF中显示在一个php文件中

  <?php
    $file = 'path of your PDF file';
    $filename = 'custom pdf file name'; /* Note: Always use .pdf at the end. */

    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="' . $filename . '"');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($file));
    header('Accept-Ranges: bytes');

    @readfile($file);
    ?>

我希望这就是您要找的

<?php
echo htmlentities(file_get_contents("yourphpfile.php"));

以下是显示另一个
.php
文件内容的一种方法:

show_included_file.php
一种方法是:
include('file.php')如果这是他们的意图,弗雷德。是的,我想你是对的。我假设OP只是想打印PHP的内容。你是想显示代码本身还是处理结果?嘿,Shankar!可能是对的。有很多方法可以做到这一点lol@user2901740你需要更清楚地知道你想要实现什么。包含/显示内容的方法有很多,我们需要知道您希望如何显示内容以及显示内容的目的。这是一个模糊的请求/问题。正如您所提到的,
但是当我试图将一个php文件显示到另一个php文件时
。此代码显示PHP文件中的内容。@ShankarDamodaran OP的问题很模糊,这就是我没有输入“答案”的原因;-)代码显示php文件的代码,而不是输出检查fredi的答案。这适合你的情况。是的,弗雷德,这就是OP想要的+1@谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢(让我们交叉手指lol)我测试了你的答案,但我得到了这些错误警告:include():无法打开“educontent/wp content/plugins/wordwork/admin/templates/tcpdf/samp/flashcards.php”以包含(include_path=”;C:\xampp\php\PEAR')在第12行的C:\xampp\htdocs\educontent\wp content\plugins\wordwork\display.php中,我只需添加一个php文件名display.php,并声明这些代码包括('educontent/wp content/plugins/wordwork/admin/templates/tcpdf/samp/flashcards.php');文件路径正确,但仍在继续errors@user2901740这显然是一个路径问题
include()
是一个全局/全局函数。尝试使用文件的实际(完整)路径。嗨,我修复了它,这是我定义的(DOC_ROOT_path,$\u SERVER['DOCUMENT_ROOT'])//回声“A$color$水果”;//一个if(isset($_POST['view']){include DOC_ROOT_PATH.“educontent/wp content/plugins/wordwork/admin/templates/target.php”}thx获取帮助:)
<?php
echo htmlentities(file_get_contents("yourphpfile.php"));
<?php
include ('file1.php');
?>
<?php
echo "This is the included file.";
?>
<?php
$variable_1 = $_POST['variable_1'];`
echo $variable_1;
?>