Example 1 — Capture Output Into a String
Start buffering, echo a message, then pull it out with ob_get_clean().
<?php
ob_start();
echo "Hello Buffer";
$text = ob_get_clean();
echo $text, PHP_EOL; How It Works
- ob_start() begins capturing output.
- echo stores text in the buffer instead of sending it yet.
- ob_get_clean() returns the string and ends the buffer.
- We print the captured text.

