php - 如何在类内启动 ob_start?

标签 php ob-start

我正在做一些关于从 php 最小化 html 的研究。喜欢

class themeing
{
    function render( $file, $folder )
    {
        if ( COMPRESS ) {
            // this is the problem
            ob_start('compressor'); 
        }

        $get = VIEWS . $folder . '/' . $file . '.phtml';

        if ( COMPRESS ) {
            ob_end_flush();
        }

        return $get;
    }

    function compressor($buffer)
    {
        $search = array(
            '/<!--(.|\s)*?-->/',
            '/\>[^\S ]+/s',
            '/[^\S ]+\</s',
            '/(\s)+/s'
        );
        $replace = array(
            '',
            '>',
            '<',
            '\\1'
        );

        $buffer = preg_replace($search, $replace, $buffer);
        return $buffer;
    }
}

问题是我怎么称呼这个 ob_start(function) ?我们可以像 ob_start($this->compresssor()) 一样吗? (好吧,我知道它失败了)在类里面?任何人 ??

谢谢你进来看看。

亚当·拉马丹

最佳答案

ob_start(array($this,'compressor'))

PHP使用array(instance,function) representation将类的成员函数表示为可调用函数。

关于php - 如何在类内启动 ob_start?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3940869/

相关文章:

javascript - 将 javascript 文件内容包含在 ob_start 缓冲区中

php - 使用 ob_start 时如何在 php 中使用 header 位置重定向?

php - 使用 PHP 删除 HTML(ob_start + dom 解析器)

即使我安装了 PHP7 并将其添加为解释器,PhpStorm 项目仍在使用 PHP5

php - mysql中的随机查询但显示新记录

php - 在 WordPress 中创建国家/地区 > 州 > 城市列表

php - 查询中的 kohana 引号

php - MySQL 有条件地从两个表中选择

php - 不能在输出缓冲显示处理程序中使用输出缓冲

PHP ob_flush() 导致错误