2016-05-16 94 views
-2

我有一个包含的PHP脚本,其中包含一个回显命令,但它没有正确显示在我的网页上。下面的代码:在PHP脚本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

为什么你有一个''回声()您的变量? – Panda

回答

1

不分配你的PHP代码variable.you可以像这样使用

$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; 
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;