What are some best practices for making changes to included files before outputting them?

When making changes to included files before outputting them, it is important to ensure that the changes are applied correctly without affecting the original files. One best practice is to use output buffering to capture the content of the included file, make the necessary changes, and then output the modified content. This way, the original file remains unchanged, and only the modified content is displayed.

<?php
ob_start();
include 'included_file.php';
$included_content = ob_get_clean();

// Make changes to the included content here
$modified_content = str_replace('old_text', 'new_text', $included_content);

echo $modified_content;
?>