IMO、最良の方法は通常、HTMLをテンプレートファイルに個別に保存することです。これは通常、入力する必要のあるいくつかのフィールドを含むHTMLを含むファイルです。次に、テンプレートフレームワークを使用して、必要に応じてhtmlドキュメントのフィールドに安全に入力できます。
Smartyは人気のあるフレームワークの1つです。これがどのように機能するかの例です(Smartyのクラッシュコースから抜粋)。
テンプレートファイル
<html>
<head>
<title>User Info</title>
</head>
<body>
User Information:<p>
Name: {$name}<br>
Address: {$address}<br>
</body>
</html>
名前とアドレスをテンプレートファイルにプラグインするPHPコード:
include('Smarty.class.php');
// create object
$smarty = new Smarty;
// assign some content. This would typically come from
// a database or other source, but we'll use static
// values for the purpose of this example.
$smarty->assign('name', 'george smith');
$smarty->assign('address', '45th & Harris');
// display it
$smarty->display('index.tpl');
Smartyの他に、好みに合わせてフレームワークをテンプレート化するための合理的な選択肢が多数あります。シンプルなものもあれば、かなり洗練された機能を備えたものもあります。