将PHP变量传递给HTML img标签中的src

时间:2018-12-17 04:07:51

标签: php html image

<?php
    $avatar_location = $_SESSION['p_avatar_location'];
    $avatar_location = "avatar/".$avatar_location;
    $avatar_location = (string)$avatar_location;
    echo "avatar location: " $avatar_location;
    ?>

<img src=$avatar_location alt="Avatar" class="avatarlogin">

我想将$avatar_location作为src传递,但显示给我的是错误图像,但是它会打印正确的图像位置:

  

头像位置:avatar / avatar5.png

我已经尝试过<img src="avatar/avatar5.png" alt="Avatar" class="avatarlogin">,并且可以正常工作。如何传递$avatar_location变量以显示图像?

2 个答案:

答案 0 :(得分:1)

使用header.liquid标签

<?php ?>

答案 1 :(得分:0)

您必须在<?php ?>内打印img标签

<?php
echo "<img src='{$avatar_location}' alt='Avatar' class='avatarlogin>";
?>