我试图让变量在用于唯一div
id的模板文件中回显,但它不断输出整个字符串并忽略php标记。我的代码和结果如下:
comment.php:
<?php
ini_set("display_errors", TRUE);
$idOfContent = 1;
$numberOfComments = 4;
while($idOfContent<=$numberOfComments){
$content = file_get_contents('comment_tmpl.php');
echo $content;
$idOfContent +=1;
}
?>
comment_tmpl.php:
<div class="Container">
<div class="Content" id="<? echo $idOfContent ?>">
<div class="PhotoContainer"> Image here </div>
<div class="CommentAndReplyContainer">
<div class="CommentBox" id="TopCommentBox_<? echo $idOfContent ?>">
<form method="post" action="comment.php">
<textarea name="comment" id="<? echo $idOfContent ?>_comment" onclick="this.value='';" > Write a comment </textarea>
<input type="hidden" name="buttonId" value="<? echo $idOfContent ?>" />
<input type="submit" id="submit" value="Post" />
</form>
</div>
</div>
</div>
</div>
结果:
<div class="Content" id="<?php echo $idOfContent ?>"></div>
如何让它识别PHP标签并正确输出变量?