2016-05-16 100 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;