Is it possible to reference an output buffer at specific depth in PHP? -



Is it possible to reference an output buffer at specific depth in PHP? -

we can ob level. can length of current ob stack. can reference ob stack @ level n? benefit of getting length of buffer @ specific depth.

suppose example:

$length = array(); ob_start(); echo "1"; $length[] = ob_get_length(); // length of current stack (depth 1) 1 ob_end_clean(); ob_start(); echo "11"; ob_start(); echo "2"; $length[] = ob_get_length(); // length of current stack (depth 2) 1 ob_end_clean(); ob_end_clean(); ob_start(); echo "111"; ob_start(); echo "22"; ob_start(); echo "3"; $length[] = ob_get_length(); // length of current stack (depth 3) 1 ob_end_clean(); ob_end_clean(); ob_end_clean(); print_r($length);

output is:

array ( [0] => 1 [1] => 1 [2] => 1 )

the length of each deepest stack 1. expected.

my app has recursive output generation , of output stacks have know length of parent system-generated stack. cannot rely on using ob_get_length() right before opening new stack because other people wrap generator in own ob stack. , break app.

are there options? thanks.

edit:

to illustrate need get:

ob_start(); echo "111"; // <-- stack of involvement ob_start(); echo "22"; ob_start(); echo "3"; $length[] = ob_get_length(); // length of current stack (depth 3) 1 $top_stack_len = get_length_of_ob_stack(1); // expected length here should 3 (strlen("111") == 3) ob_end_clean(); ob_end_clean(); echo "some more chars alter length of stack 1"; ob_end_clean(); echo $top_stack_len; // i'm expecting see 3 here.

updated:

you create class handle it. believe class plenty allow me know if need futher help.

class ob { static protected $_level = 0; static protected $_data = array(); static function start() { ob_flush(); self::$_level++; ob_start("ob::store"); } static function end() { ob_end_flush(); self::$_level--; } static function length($level) { ob_flush(); homecoming strlen(self::$_data[$level]); } static function store() { if(self::$_level != 0) self::$_data[self::$_level] .= ob_get_contents(); } static function printdata() { print_r(self::$_data); } }

example:

ob::start(); echo '1'; ob::start(); echo '2222'; ob::start(); echo '2'; echo ob::length(1); echo ob::length(2); echo ob::length(3); ob::end(); echo ob::length(1); echo ob::length(2); echo ob::length(3); ob::end(); echo ob::length(1); echo ob::length(2); echo ob::length(3); ob::end(); echo ob::length(1); echo ob::length(2); echo ob::length(3); ob::printdata();

php

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -