<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 4 Fantastic PHP Output Buffering Tricks for Web Developers</title>
	<atom:link href="http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers/feed" rel="self" type="application/rss+xml" />
	<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers</link>
	<description>Become a Better Developer, One Tip at a Time.</description>
	<lastBuildDate>Wed, 04 Aug 2010 15:39:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<item>
		<title>By: Stalingrad</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1843</link>
		<dc:creator>Stalingrad</dc:creator>
		<pubDate>Wed, 04 Aug 2010 15:39:50 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1843</guid>
		<description>function remove_space_and_compress($buffer)
    {
    $buffer=trim(preg_replace(&#039;/\s+/&#039;, &#039; &#039;, $buffer));

    if (stristr($_SERVER[&#039;HTTP_ACCEPT_ENCODING&#039;], &#039;gzip&#039;) !== FALSE)
        {
        $buffer=gzencode($buffer);
        header(&#039;Content-Encoding: gzip&#039;);
        }
    else if (stristr($_SERVER[&#039;HTTP_ACCEPT_ENCODING&#039;], &#039;deflate&#039;) !== FALSE)
        {
        $buffer=gzdeflate($buffer);
        header(&#039;Content-Encoding: deflate&#039;);
        }

    return $buffer;
    }

ob_start(&#039;remove_space_and_compress&#039;);

/* After looking at your function i decided to optimize it :) */</description>
		<content:encoded><![CDATA[<p>function remove_space_and_compress($buffer)<br />
    {<br />
    $buffer=trim(preg_replace(&#8216;/\s+/&#8217;, &#8216; &#8216;, $buffer));</p>
<p>    if (stristr($_SERVER['HTTP_ACCEPT_ENCODING'], &#8216;gzip&#8217;) !== FALSE)<br />
        {<br />
        $buffer=gzencode($buffer);<br />
        header(&#8216;Content-Encoding: gzip&#8217;);<br />
        }<br />
    else if (stristr($_SERVER['HTTP_ACCEPT_ENCODING'], &#8216;deflate&#8217;) !== FALSE)<br />
        {<br />
        $buffer=gzdeflate($buffer);<br />
        header(&#8216;Content-Encoding: deflate&#8217;);<br />
        }</p>
<p>    return $buffer;<br />
    }</p>
<p>ob_start(&#8216;remove_space_and_compress&#8217;);</p>
<p>/* After looking at your function i decided to optimize it <img src='http://dev-tips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  */</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1837</link>
		<dc:creator>Kris</dc:creator>
		<pubDate>Fri, 30 Jul 2010 09:27:16 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1837</guid>
		<description>balls, it all got encoded
the ... becomes &#039;ampersand hash 8230;&#039; 
then it gets encoded again to
&#039;ampersand amp; hash 8230&#039;</description>
		<content:encoded><![CDATA[<p>balls, it all got encoded<br />
the &#8230; becomes &#8216;ampersand hash 8230;&#8217;<br />
then it gets encoded again to<br />
&#8216;ampersand amp; hash 8230&#8242;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1836</link>
		<dc:creator>Kris</dc:creator>
		<pubDate>Fri, 30 Jul 2010 09:25:31 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1836</guid>
		<description>if you look at this code 
&lt;code&gt;
// add ellipses
$buffer = str_replace(&#039;...&#039;, &#039;&#8230;&#039;, $buffer);
// encode ampersands
$buffer = str_replace(&#039;&amp;&#039;, &#039; &amp; &#039;, $buffer);
&lt;/code&gt;

let&#039;s say we had the following content in our buffer
&lt;code&gt;
this is great... and it&#039;s fast &amp; fun
&lt;/code&gt;

won&#039;t this get messed up.  specifically the str_replace will change the ... into &#8230; and then process it again to make &#8230;

haven&#039;t actually tried this, it was just my first thought when looking at it.</description>
		<content:encoded><![CDATA[<p>if you look at this code<br />
<code><br />
// add ellipses<br />
$buffer = str_replace('...', '&#8230;', $buffer);<br />
// encode ampersands<br />
$buffer = str_replace('&amp;', ' &amp; ', $buffer);<br />
</code></p>
<p>let&#8217;s say we had the following content in our buffer<br />
<code><br />
this is great... and it's fast &amp; fun<br />
</code></p>
<p>won&#8217;t this get messed up.  specifically the str_replace will change the &#8230; into &#8230; and then process it again to make &#8230;</p>
<p>haven&#8217;t actually tried this, it was just my first thought when looking at it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adrenalin</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1648</link>
		<dc:creator>Adrenalin</dc:creator>
		<pubDate>Wed, 03 Feb 2010 17:53:53 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1648</guid>
		<description>One of my late favorites is ob_implicit_flush() which works pretty much exactly opposite to your suggestions. Flushing the output buffer constantly is very nice especially when running batches that take long to finish, since it&#039;s possible to see the results on the fly.</description>
		<content:encoded><![CDATA[<p>One of my late favorites is ob_implicit_flush() which works pretty much exactly opposite to your suggestions. Flushing the output buffer constantly is very nice especially when running batches that take long to finish, since it&#8217;s possible to see the results on the fly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 45 Must Read PHP Articles and Resources</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1472</link>
		<dc:creator>45 Must Read PHP Articles and Resources</dc:creator>
		<pubDate>Fri, 08 Jan 2010 17:45:07 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1472</guid>
		<description>[...] 4 Fantastic PHP Output Buffering Tricks for Web Developers [...]</description>
		<content:encoded><![CDATA[<p>[...] 4 Fantastic PHP Output Buffering Tricks for Web Developers [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Resources for PHP Webmail &#171; David Woodfield</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1104</link>
		<dc:creator>Resources for PHP Webmail &#171; David Woodfield</dc:creator>
		<pubDate>Tue, 24 Nov 2009 17:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1104</guid>
		<description>[...] http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers" rel="nofollow">http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-1000</link>
		<dc:creator>Craig</dc:creator>
		<pubDate>Wed, 14 Oct 2009 06:50:15 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-1000</guid>
		<description>So what about if you want all of that in one script. How do you combine everything?</description>
		<content:encoded><![CDATA[<p>So what about if you want all of that in one script. How do you combine everything?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffM</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-931</link>
		<dc:creator>JeffM</dc:creator>
		<pubDate>Thu, 03 Sep 2009 16:46:59 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-931</guid>
		<description>Hi Mark

That&#039;s an interesting question. What&#039;s encoding them before they&#039;re sent to the output buffer? How about a usage example?</description>
		<content:encoded><![CDATA[<p>Hi Mark</p>
<p>That&#8217;s an interesting question. What&#8217;s encoding them before they&#8217;re sent to the output buffer? How about a usage example?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mark</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-926</link>
		<dc:creator>mark</dc:creator>
		<pubDate>Tue, 01 Sep 2009 22:07:54 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-926</guid>
		<description>hi. how would i do the reverse of this. i.e. convert only encoded ampersands that are in hrefs to a straight &amp;? backwards i know but i need to do this and my brain hurts. thanks!</description>
		<content:encoded><![CDATA[<p>hi. how would i do the reverse of this. i.e. convert only encoded ampersands that are in hrefs to a straight &amp;? backwards i know but i need to do this and my brain hurts. thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JeffM</title>
		<link>http://dev-tips.com/featured/4-fantastic-php-output-buffering-tricks-for-web-developers#comment-917</link>
		<dc:creator>JeffM</dc:creator>
		<pubDate>Fri, 28 Aug 2009 10:34:51 +0000</pubDate>
		<guid isPermaLink="false">http://dev-tips.com/?p=330#comment-917</guid>
		<description>@Patrik:
Place the &lt;code&gt;ob_start()&lt;/code&gt; right at the top of your Wordpress theme&#039;s &lt;code&gt;functions.php&lt;/code&gt; file. This file is loaded before any ouput is generated (other than headers, natch).

&lt;code&gt;
// file = theme\functions.php
// Start output buffering

ob_start(&#039;ob_postprocess&#039;); 

function ob_postprocess($buffer)  
	
	// do your thang here

	// finally send it to the browser
	return $buffer;
}

// remainder of functions.php...

&lt;/code&gt;

The &lt;code&gt;ob_end_flush()&lt;/code&gt; call could be added at the end of your theme&#039;s &lt;code&gt;footer.php&lt;/code&gt;, but is not strictly required since the callback function will be called regardless. My experience anyways, since PHP5+.</description>
		<content:encoded><![CDATA[<p>@Patrik:<br />
Place the <code>ob_start()</code> right at the top of your WordPress theme&#8217;s <code>functions.php</code> file. This file is loaded before any ouput is generated (other than headers, natch).</p>
<p><code><br />
// file = theme\functions.php<br />
// Start output buffering</p>
<p>ob_start('ob_postprocess'); </p>
<p>function ob_postprocess($buffer)  </p>
<p>	// do your thang here</p>
<p>	// finally send it to the browser<br />
	return $buffer;<br />
}</p>
<p>// remainder of functions.php...</p>
<p></code></p>
<p>The <code>ob_end_flush()</code> call could be added at the end of your theme&#8217;s <code>footer.php</code>, but is not strictly required since the callback function will be called regardless. My experience anyways, since PHP5+.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
