-3

I'm relatively new to php & was wondering if I can pass echo statement within variable. I have this in wordpress trying to retrieve profile picture using variable id to be able to integrate in wp comment section. Tried this.

$idd= author_details(get_the_ID());

$authordata = get_userdata( $idd );

$au=$authordata->display_name;

$authorAvatar = '<img src="http://www.example.com/photos/<?php echo getimg($au);?>" class="avatar user-1-avatar avatar-28 photo" width="40" height="40" alt="profile pic" >';

Here is the result image url I'm getting:

http://www.example.com/photos/%3C?php%20echo%20getimg($au);?%3E

It's apparent that I cannot pass echo statement within variable, but the sad thing is I'm unable to find solution for this simple stuff.

Note: The code works perfectly when they are put outside variable.

Voluntary help will be highly appreciated. Thanks.

Nurjan
  • 5,889
  • 5
  • 34
  • 54
Jay Bro
  • 23
  • 2
  • 10
  • 1
    Please have a read up on [strings in PHP](http://php.net/manual/en/language.types.string.php). – Jonnix Nov 24 '16 at 10:30

1 Answers1

1

You don't need the PHP tags in the middle.

$var = getimg($au);
$authorAvatar = '<img src="http://www.example.com/photos/'.$var.'" class="avatar user-1-avatar avatar-28 photo" width="40" height="40" alt="profile pic" >';
Antony Thompson
  • 1,608
  • 1
  • 13
  • 22