What are the potential pitfalls of using a single PHP file for both script execution and HTML generation?

Using a single PHP file for both script execution and HTML generation can lead to messy and hard-to-maintain code. To solve this issue, it's recommended to separate PHP logic from HTML presentation by using a template engine like Smarty or Twig.

<?php
// Include the template engine library
require_once 'path/to/template-engine.php';

// Initialize the template engine
$template = new TemplateEngine();

// Assign variables to the template
$template->assign('name', 'John Doe');
$template->assign('age', 30);

// Display the template
$template->display('path/to/template-file.tpl');
?>