我试图让变量在用于唯一div
ID 的模板文件中回显,但它一直输出整个字符串并忽略 php 标签。我的代码和结果如下:
评论.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;
}
?>
评论_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 标签并正确输出变量?