What PHP function can be used to save dynamic content as a static page and update it when there are changes in the database?

To save dynamic content as a static page and update it when there are changes in the database, you can use a combination of PHP functions like ob_start(), ob_get_contents(), file_put_contents(), and a database trigger to detect changes and trigger the update process.

<?php
ob_start();

// Your dynamic content generation code here
// Example: 
echo "Hello, World!";

$content = ob_get_contents();
ob_end_clean();

// Save the dynamic content as a static HTML file
$file = 'static_page.html';
file_put_contents($file, $content);

// Database trigger to detect changes and update the static page
// Example: 
// CREATE TRIGGER update_static_page AFTER INSERT ON your_table FOR EACH ROW
// BEGIN
//     // Update the static page here
//     file_put_contents($file, "New content based on database changes");
// END;
?>