How can a template system be implemented in PHP to simplify the process of replacing placeholders with variables in a text file?

To implement a template system in PHP, you can create a function that takes a text file with placeholders and an array of variables to replace those placeholders with the actual values. The function can use PHP's `str_replace` function to replace the placeholders with the variables.

function render_template($template_file, $variables) {
    $template = file_get_contents($template_file);
    
    foreach ($variables as $key => $value) {
        $template = str_replace("{{$key}}", $value, $template);
    }
    
    return $template;
}

// Example of how to use the render_template function
$template_file = 'template.txt';
$variables = array(
    'name' => 'John Doe',
    'email' => 'john.doe@example.com'
);

echo render_template($template_file, $variables);