2

The function getUserAvatar outputs the following :

 <img src="http://pathtoimage/image.jpg" height="16" width="16" alt="avatar" />

I'm calling it within a particular div.

When I call it like this is works perfectly :

 echo '<div class="avatar">';
 echo getUserAvatar($avatar_id);
 echo '</div>';

Resulting in the following html output :

 <div class="avatar"><img src="http://pathtoimage/image.jpg" height="16" width="16" alt="avatar" /></div>

But when I try to put it all on one line :

 echo '<div class="avatar">' .getUserAvatar($avatar_id). '</div>';

It results in the following html, executing the function before rendering the div tags? :

 <img src="http://pathtoimage/image.jpg" height="16" width="16" alt="avatar" /><div class="avatar"></div>

Could somebody please explain why this is and offer the correct solution?

2
  • 2
    are you returning or printing content in your getUserAvatar function? Commented Mar 22, 2015 at 11:22
  • 1
    you have to return the string in your getUserAvatar. Commented Mar 22, 2015 at 11:23

1 Answer 1

1
<?php
function getUserAvatar($avatar_id) {
    // your function body
    return $your_return_id;
}

echo '<div class="avatar">' .getUserAvatar($avatar_id). '</div>';
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.