2017-05-08 89 views
1

我試圖顯示HTML像echo $ contentsArray [0];在PHP中,但圖像不顯示。 因爲img路徑顯示爲"<?=POST_IMG?>post/item/mypost/post_1.png"而不是 "img/PostImg/post/item/mypost/post_1.png"。我應該如何解決這個問題。無法正確顯示圖像路徑從PHP陣列

define('POST_IMG', 'img/PostImg/'); 

$item1 = '<a href="#" target="_blank"> <div class="left"> 
       <img src="<?=POST_IMG?>post/item/mypost/post_1.png"> 
      </div></a>'; 

$contentsArray = array($item1, ...More 
+0

它是一個字符串到PHP所以做這樣的''。你只需要在你的字符串中形成一個變量 –

回答

1

那麼你有你的代碼中的串聯問題。 你可以參考下面的代碼,

注:最好是避免使用簡短的PHP標籤

define('POST_IMG', 'img/PostImg/'); 

$contentsArray = array('<a href="#" target="_blank"> 
     <div class="left"> 
      <img src= "'.POST_IMG.'post/item/mypost/post_1.png"> 
     </div> 
</a>', ...More