Forum Moderators: coopster

Message Too Old, No Replies

output control function

A theoretical question

         

henry0

12:37 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A user in Webmaster general mentioned something about
output_control_function
Out of curiosity I checked the manual
But I am not sure I got it correct:
Does using the function act as if OB is turned on?
If used in an environment where OB in the php.ini is Off.

It does not matter to me since I run my server and OB is ON
But in the case where a user can not access its php.ini it could become handy if the result is similar to OB On.

But again I am not sure that I understand it correctly :)

coopster

8:54 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



output_control_function

?
Do you mean Output Control Functions [php.net]?

henry0

9:37 pm on Mar 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, yes .. typo!

cmarshall

12:32 am on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use them all the time. Very easy to use. They don't affect headers, but I always use them after headers.

The most obvious use is to optimize output. I have code at the end of my output that looks like this:


ob_start();

.
.
.

$opt = ob_get_contents ( );
ob_end_clean();
if(!$purty )
{
$opt = preg_replace("/(\s+?)¦(<!--.+?-->)/"," ", $opt);
$opt = preg_replace("/\s{2,}/"," ",$opt);
$opt = str_replace("> <","><",$opt);
}
echo $opt;

This turns the code into a big ugly stream of optimized text. It allows me to fill my code with comments and formatting without penalty.

It will interfere with JavaScript, however. Since I try to avoid putting a whole lot of JS into my production pages (I do use it for admin, but try to keep it away from my users), this doesn't need to be much of a problem.

NOTE: I should be able to do this:

$opt = preg_replace("/(\s{2,}?)¦(\s*<!--.+?-->\s*)/"," ", $opt);

But the regex doesn't quite work, and I'm too lazy to figure it out. regex can be a real brain squeeze.

cmarshall

2:20 am on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yaknowhut?

I just figgered that since I was in there, I'd take another lil' ol' peek at that regex, and came up with this:

$opt = preg_replace( "/>\s*?</","><", preg_replace( "/(\s+)¦(\s*<!--.+?-->\s*)/"," ", $opt ) );

henry0

1:20 pm on Mar 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I see thank you!