【问题标题】:ob_get_content() output incorrectob_get_content() 输出不正确
【发布时间】:2015-01-08 16:23:00
【问题描述】:

我在使用 ob_start 函数时遇到了一些问题,可能是由于新的 PHP 5.5

我要做的是使用内部 ob_start 从第三个文件渲染一些 PHP。

代码如下:

function fetch()
{
    extract($this->a_vars); // Extract the vars to local namespace

    ob_start();                                              

    include (templateClass.php);  // This file is just 'text'
    $s_contents = ob_get_contents();

    ob_end_clean();

    return $s_contents;
}

基本上我所做的是在本地命名空间中提取一些变量,templateClass 将使用这些变量来呈现/显示一些文本,例如:

...

function func1() {
    return true;
}

<?if(isset($var1)):?>
    function func2() {
        return 2;
    }
<?endif;?>

...

但是我的变量 $s_contents 包含文件的所有内容,包括里面没有被解释的 php 代码。我需要的是解释所有 php 块,输出将是我最终可用的 PHP 类。

有什么想法吗?

【问题讨论】:

  • &lt;? 您确定在php.ini 中启用了short_open_tag 吗?缺少引号? include (templateClass.php);
  • short_open_tag 处于活动状态...并且文件看起来没问题。

标签: php ob-start php-5.5 ob-get-contents


【解决方案1】:
  1. include (templateClass.php);
    我希望你在里面加上引号。喜欢include ("templateClass.php");

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2015-03-10
    • 2014-04-01
    • 2018-03-10
    • 2018-09-13
    • 1970-01-01
    相关资源
    最近更新 更多