1

Im trying to display the html like echo $contentsArray[0]; in php, however the image is not displayed. since, the img path is displayed like "<?=POST_IMG?>post/item/mypost/post_1.png" instead of "img/PostImg/post/item/mypost/post_1.png". How should I fix this problem.

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 
1
  • Its a string to php so do like this <img src="'.POST_IMG.'post/item/mypost/post_1.png">. You just have to concatinate the variable in your string Commented May 8, 2017 at 5:29

1 Answer 1

1

Well you have problem with the concatenation inside your code. you can refer following code,

Note : it is better to avoid use of short-hand php tag

 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.