daviga404
daviga404

Reputation: 538

Capture content after function is called

Is it possible (in PHP) to call a function that triggers some capturing process so all HTML output after that function is captured up until an ending function? For example, some profiling applications do very similar procedures to this, and with functions such as ob_start(), it seems logical to me. Example of concept:

<?php beginSection("hello"); ?>
<b>Hi there!</b>
<?php endSecton("hello"); ?>
<!-- Section "hello" now contains "<b>Hi there!</b>" -->

Upvotes: 0

Views: 50

Answers (1)

Niels Keurentjes
Niels Keurentjes

Reputation: 41968

The way output buffering works does not allow you do this in a named fashion - ob_start and its friends stack on eachother, and unwind in order. You could implement it like this:

<?php ob_start(); ?>
<b>Hi there!</b>
<?php $sections['hello'] = ob_end_clean(); ?>

This would answer your question.

Upvotes: 2

Related Questions