How can output buffering in PHP be effectively used to capture and store processed data for writing into a new CSV file?

To use output buffering in PHP to capture and store processed data for writing into a new CSV file, you can start by turning on output buffering using the ob_start() function. Then, you can output the processed data using echo or print statements. Finally, you can store the captured output in a variable using ob_get_clean() and write it to a new CSV file using file_put_contents() or fwrite().

<?php
// Turn on output buffering
ob_start();

// Process and output data
echo "Name, Age\n";
echo "John Doe, 30\n";
echo "Jane Smith, 25\n";

// Store captured output in a variable
$output = ob_get_clean();

// Write captured output to a new CSV file
file_put_contents('output.csv', $output);
?>