Vaheed01
Vaheed01

Reputation: 1057

change php output buffer before flush

Is there anyway to change output buffer before flush it? I tried this function ob_set_contents but it seems there is no such a function, I have the following in my header.php file:

ob_start(null,0,PHP_OUTPUT_HANDLER_CLEANABLE);

I need to do such a following in end of my footer.php file:

$output = ob_get_contents();
$output=str_ireplace("<-BlogXmlLink->","/en/rss.xml",$output);
ob_set_contents($output);
ob_end_flush();

Upvotes: 0

Views: 202

Answers (1)

kabanus
kabanus

Reputation: 25895

Check the manual regarding ob_start parameters. From here:

output_callback

An optional output_callback function may be specified. This function takes a string as a parameter and should return a string. The function will be called when the output buffer is flushed (sent) or cleaned (with ob_flush(), ob_clean() or similar function) or when the output buffer is flushed to the browser at the end of the request. When output_callback is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser. If the output_callback is not a callable function, this function will return FALSE. This is the callback signature:

string handler ( string $buffer [, int $phase ] )

So instead of null to your second argument put a function that performs:

function($output) { return str_ireplace("<-BlogXmlLink->","/en/rss.xml",$output); }

Upvotes: 1

Related Questions