1

約2000ファイルのテキストのブロックを置き換え、include('myText.php');に置き換える必要があります。

ここでの問題は、それがhtmlファイルにあるということです。その場合、私もphpタグを入れる必要がありますが、それを行う方法が見つかりません。

これが私のコードです

$start = "<is_comment>";
 $end = "</is_comment>";

 $startChain = strpos($fileContent, $start);

 $endChain = strpos($fileContent, $end) + strlen($end);


 $text = substr($fileContent, $startChain, $endChain - $startChain);
 //echo htmlspecialchars($text);

 $content = str_replace($text, "<?php include('showISComment.php?project=$project'); ?>", file_get_contents($file));

そして、それを実行しているphpファイルで、phpタグを配置すると、テキストとしてではなく、自動的にタグとして識別されます。

ありがとう


showISComment.php例を示すために(要求に応じて)、 aを取得して戻り値または:stringを返す関数が宣言されていると仮定します。"true""false"

// showISComment.php
function isComment($project) {
    if (...) {
        return "true";
    } else {
        return "false";
    }
}

今あなたのコードで、このようなことをしてください:

require_once("showISComment.php");
// ...
$replace_text = isComment($project);
$content = str_replace($text, $replace_text, file_get_contents($file));
4

1 に答える 1

0

(要求に応じて)例を挙げると、showISComment.phpa を取得してorstringを返す関数が宣言されていると仮定します。"true""false"

// showISComment.php
function isComment($project) {
    if (...) {
        return "true";
    } else {
        return "false";
    }
}

コードで、次のようにします。

require_once("showISComment.php");
// ...
$replace_text = isComment($project);
$content = str_replace($text, $replace_text, file_get_contents($file));
于 2013-02-14T15:48:00.180 に答える