How can PHP be effectively separated from HTML in a forum script?

To effectively separate PHP from HTML in a forum script, you can use a template system such as Smarty or Twig. These template engines allow you to keep your PHP logic separate from your HTML markup, making your code cleaner and more maintainable.

// Example using Smarty template engine
require_once('smarty/Smarty.class.php');

$smarty = new Smarty;
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'templates_c';

// Assign variables to be used in the template
$smarty->assign('title', 'Forum Title');
$smarty->assign('posts', $posts);

// Display the template
$smarty->display('forum_template.tpl');