What is a template system in PHP and how does it work?

A template system in PHP is a way to separate the presentation layer from the business logic in a web application. It allows developers to create reusable templates for displaying data and formatting content. By using a template system, developers can easily update the design of a website without having to modify the underlying code.

// Example of using a template system in PHP
$template = 'Hello, <?php echo $name; ?>';
$name = 'John Doe';

// Replace placeholders with actual data
eval("?>$template<?php ");

// Output: Hello, John Doe