包括「&书信电报;?php包括(';myfile.php';)”;在带有str_replace的html文件中

包括「&书信电报;?php包括(';myfile.php';)”;在带有str_replace的html文件中,php,tags,str-replace,Php,Tags,Str Replace,我必须替换大约2000个文件中的一块文本,并用include('myText.php')替换它 这里的问题是,它在一个html文件中。在这种情况下,我还需要将php标记放入其中 但是我找不到一个方法去做 这是我的密码 $start = "<is_comment>"; $end = "</is_comment>"; $startChain = strpos($fileContent, $start); $endChain = strpos($fileContent

我必须替换大约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));
$start=”“;
$end=“”;
$startChain=strpos($fileContent,$start);
$endChain=strpos($fileContent,$end)+strlen($end);
$text=substr($fileContent,$startChain,$endChain-$startChain);
//echo htmlspecialchars($text);
$content=str_replace($text,“,file_get_contents($file));
在我正在做的php文件中,当我放置php标记时,它不会将其标识为文本,而是自动标识为标记

感谢给您一个示例(根据要求),我假设在
showISComment.php
中声明了一个函数,它获取
字符串
,并返回
“true”
“false”

现在在代码中,执行以下操作:

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

为什么不先使用
showISComment.php
中声明的函数生成
replace\u text
,然后执行:
$content=str\u replace($text,$replace\u text).html
,因此当您访问它时,它不会通过PHP处理器。您需要将其重命名为something.php。此外,您可以使用
substr\u replace()
,而不是
str\u replace()
@Bamar:我无法重命名它。。大约有2000个这样的文件。我想要的是在文本替换中集成php标记“”。先生,你可能是个天才。。让我们试试这个解决方案
require_once("showISComment.php");
// ...
$replace_text = isComment($project);
$content = str_replace($text, $replace_text, file_get_contents($file));