How to run ob_start inside a class?

im doing a little research regarding html minimization from php. as

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;
    }
}

The problem is, what do I call it ob_start (function)? can we do ob_start ($ this-> compresssor ())? (ok, i know this is not) inside the class? is anyone

Thanks for watching.

Adam Ramadhan

+3
source share
1 answer
ob_start(array($this,'compressor'))

PHP uses the representation of array (instance, function) to represent member functions of classes as called functions.

+14
source

Source: https://habr.com/ru/post/1769712/


All Articles