私自身の関数では、最初にinclude
1つのhtml
ファイルを作成し、次にそのインクルードファイルで別のファイル名を見つけた場合、html
最初にインクルードされたファイルと2番目にインクルードされたファイルのコンテンツをマージします。
function inc($html){
$include_pattern = "\{\s*include\s*(\(|')\s*([a-zA-Z0-9-.\/-_]+)\s*(\)|')\s*\}";
preg_match_all("/$include_pattern/s",$html,$match);
if($len = count($match[0])){
$i=0;
while($i<$len){
$file = preg_replace("/$include_pattern/s","$2",$match[0][$i]);
ob_start();
include($file);
$output = ob_get_contents();
ob_end_clean();
//$output = $this->inc($output);
$html = str_replace($match[0][$i],$output,$html);
$i++;
}
return $html;
}
}
この関数では、コードのコメント部分を見ると、2番目のインクルードhtml
ファイルのコンテンツを取得しようとしました。想像してみてください。1.html
このインクルードされたファイルに含まれている場合、コンテンツとコンテンツを2.html
どのように表示できますか?2.html
1.html
下の画像を見ると、現在のトピックを理解していることがわかります。(画像の「結果ボックス」のような結果を取得したい)。