【问题标题】:include file content php包含文件内容 php
【发布时间】:2011-11-30 15:06:32
【问题描述】:

我想将 php 文件中的内容包含到另一个 php 文件中。 (它在一个 wordpress 网站上)
Include 或 require 不起作用,因为它只是包含文件,我需要内容本身。
file_get_contents 也不起作用,因为它只显示我的 php 代码而不执行它。

我必须使用什么功能?

【问题讨论】:

  • includerequire 都执行代码。你到底需要什么?您需要将脚本回显的内容存储在变量中吗?
  • 你能澄清一下“内容”是什么意思吗?
  • 在黑暗中肆无忌惮地刺杀......包含文件中是否有 php 标签('强烈建议您在了解有关 php 的更多信息之前不要这样做。

标签: php file include


【解决方案1】:

我也不完全理解你的问题,但我认为这可能对你有用:

ob_start();
include('yourfile.php');
$contents = ob_get_clean();

$contents 现在将包含您的 PHP 脚本的“内容”(输出)。

【讨论】:

    【解决方案2】:

    Include 或 require 不起作用,因为它只是包含文件

    暂停。什么? Include 为您在文件中包含代码。我确定这就是你想要的。例如,请参见下面的代码。 test.php 包含 vars.php 并能够回显来自 vars.php 的变量

    //vars.php
    ----------
    <?php
    
    $color = 'green';
    $fruit = 'apple';
    
    ?>
    ----------
    
    //test.php
    ----------
    <?php
    
    echo "A $color $fruit"; // A
    
    include 'vars.php';
    
    echo "A $color $fruit"; // A green apple
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-28
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      相关资源
      最近更新 更多