0

私自身の関数では、最初にinclude1つの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.html1.html

下の画像を見ると、現在のトピックを理解していることがわかります。(画像の「結果ボックス」のような結果を取得したい)。

ここに画像の説明を入力してください

4

1 に答える 1

0

関数の問題を修正しました。機能が変更され、うまく機能しています...

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();

        $html = str_replace($match[0][$i],$output,$html);

$i++; 
     }
return inc($html); 
       }else{
     return $html;
   }
}
于 2012-12-10T13:23:04.667 に答える