我有一个包含echo命令的php脚本,但它没有正确显示在我的网页上。这是代码:
<?php
$content_sql = "SELECT * FROM mag_books WHERE id = '$id'";
$content_res = mysqli_query($con, $content_sql);
while($content = mysqli_fetch_assoc($content_res)){
$content_intro = nl2br($content["intro"]);
$display_content = "
<div class=\"pageSection text\">
$content_article
</div>
<div class=\"pageSection text\">
$folder = 'files/books/'.$post_year.'/'.$post_id.'/';
$filetype = '*.{jpg}*';
$files = glob($folder.$filetype, GLOB_BRACE);
foreach ($files as $file)
{
echo '
<div class=\"galleryCell\">
<img class=\"galleryPhoto\" src=\"files/books/'.$file.'\" />
</div>
';
}
</div>
";
};
?>
在我的网站上显示:
= 'files/books/'.2016.'/'.1463391024.'/'; = '*.{jpg}*'; = glob(., GLOB_BRACE); foreach ( as ) { echo '
'; }
如何逃避代码以显示应该回显的内容?
答案 0 :(得分:1)
你没有将你的PHP代码分配给变量。你可能会像这样使用
$display_content ='';
$display_content .= "<div class=\"pageSection text\">".$content_article."</div><div class=\"pageSection text\">";
$folder = 'files/books/'.$post_year.'/'.$post_id.'/';
$filetype = '*.{jpg}*';
$files = glob($folder.$filetype, GLOB_BRACE);
foreach ($files as $file)
{
$display_content .="<div class=\"galleryCell\"><img class=\"galleryPhoto\" src=\"files/books/".$file."\" /></div>";
}
$display_content .= "</div>";
echo $display_content;
答案 1 :(得分:0)
试试这样:
$display_content = '';
while($content = mysqli_fetch_assoc($content_res)){
$content_intro = nl2br($content["intro"]);
$display_content .= '
<div class="pageSection text">
' . $content_article . '
</div>
<div class="pageSection text">';
$folder = 'files/books/'.$post_year.'/'.$post_id.'/';
$filetype = '*.{jpg}*';
$files = glob($folder . $filetype, GLOB_BRACE);
foreach ($files as $file) {
$display_content .= '
<div class="galleryCell">
<img class="galleryPhoto" src="files/books/'.$file.'" />
</div>';
}
$display_content .= '
</div>';
}
echo $display_content;