2016-05-16 13 views
-2

私はechoコマンドを含むphpスクリプトを持っていますが、それは私のWebページに正しく表示されません。ここでは、コードがあります:私のウェブサイト上で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

あなたがvariable.youに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; 
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;