[英]Looping HTML code inside php while loop
我希望HTML代码在每次执行while()
之后重复。 但这不是重复。
实际上,我希望它在每一行上都读取一个在底部带有注释和类似按钮的框。 因此,我将HTML代码保留在while
循环中,但是在运行代码后,将每个执行行都写在同一框中。
这是代码参考:
<?php
$name = $_POST['name'];
$query = $_POST["query"];
$po = "$name-$query";
$myfile = fopen("posts.txt", "a+");
fwrite($myfile,$po);
fclose($myfile);
$mypost=fopen("posts.txt","r");
while(!feof($mypost)): ?> <!-- with this while loop i want this div class to repeat -->
<div class="w3-container w3-card w3-white w3-round w3-margin"><br>
<img src="/w3images/avatar2.png" alt="Avatar" class="w3-left w3-circle w3-margin-right" style="width:60px">
<span class="w3-right w3-opacity">1 min</span>
<h4>fdg</h4><br>
<hr class="w3-clear">
<p> <?php
echo fgets($mypost);
?></p>
<button type="button" class="w3-button w3-theme-d1 w3-margin-bottom"><i class="fa fa-thumbs-up"></i> Like</button>
<button type="button" class="w3-button w3-theme-d2 w3-margin-bottom"><i class="fa fa-comment"></i> Comment</button>
</div>
<?php endwhile; ?>
请帮我该怎么办?
一个简单的原因为何在php代码块{}中对HTML代码使用相关字符串的回显
<?php
$name = $_POST['name'];
$query = $_POST["query"];
$po = "$name-$query";
$myfile = fopen("posts.txt", "a+");
fwrite($myfile,$po);
fclose($myfile);
$mypost = fopen("posts.txt","r");
while(!feof($mypost)) {
echo '<div class="w3-container w3-card w3-white w3-round w3-margin"><br>
<img src="/w3images/avatar2.png" alt="Avatar" class="w3-left w3-circle w3-margin-right" style="width:60px">
<span class="w3-right w3-opacity">1 min</span>
<h4>fdg</h4><br>
<hr class="w3-clear">
<p>'. fgets($mypost)
. '</p>
<button type="button" class="w3-button w3-theme-d1 w3-margin-bottom"><i class="fa fa-thumbs-up"></i> Like</button>
<button type="button" class="w3-button w3-theme-d2 w3-margin-bottom"><i class="fa fa-comment"></i> Comment</button>
</div>';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.