在带有str_replace的html文件中包含“<! - ?php include('myfile.php')” - >

时间:2013-02-14 15:31:14

标签: php tags str-replace

我必须替换大约2 000个文件中的文本块,并用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标签时,它并未将其识别为文本,而是自动将其标识为标签。

感谢

1 个答案:

答案 0 :(得分:0)

为了给你一个例子(根据要求),我假设在showISComment.php中声明了一个获得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));