【发布时间】: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 类。
有什么想法吗?
【问题讨论】:
-
<?您确定在php.ini中启用了short_open_tag吗?缺少引号?include (templateClass.php); -
short_open_tag 处于活动状态...并且文件看起来没问题。
标签: php ob-start php-5.5 ob-get-contents