dongqu9917 2015-10-09 23:58
浏览 52
已采纳

PHP显示图像BLOB来自MySQL内部echo <_END

I'm trying to display a image from MySQL and it works like this:

echo "<tbody>";
    echo "<tr>";
        echo "<td>$linha[receita_id]";
        echo '<td><img src="data:image/jpeg;base64,'.base64_encode( $linha['image'] ).'"/>';
    echo "</tr>";
echo "</tbody>";

What I want to do it to use php echo <<<_END because I have a lot more lines of code, and I don't want to type lots of "echo" for every line. So I have this below, but It doesn't work! I tryed all types of different escape characters, but still nothing.

echo <<<_END
    <tbody>
        <tr>
            <td>$linha[receita_id]
            <td><img src="data:image/jpeg;base64,'.base64_encode( $linha[image] ).'"/>
        </tr>
    </tbody>                
_END;

The line with $linha[receita_id] works perfectly! But the other doesn't.

Any ideas?

  • 写回答

3条回答 默认 最新

  • duano3557 2015-10-10 00:18
    关注

    Unfortunately, you can't call functions from within heredoc. The best you can do is to assign a variable with the value you want to output, e.g.

    $base64_encoded_image = base64_encode( $linha["image"] );
    echo <<<_END
        <tbody>
            <tr>
                <td>$linha[receita_id]
                <td><img src="data:image/jpeg;base64,{$base64_encoded_image}"/>
            </tr>
        </tbody>                
    _END;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?