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?

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;

Well, first I think this is not a good idea for displaying content using PHP in that way, but if you want to save your initial idea, you can compose a variable and use concatenation, for example:

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

echo $content;

Use " instead of ', quotation marks have better performance than single quote.

The another way to display (if you will diplay it in browser), use only tags of PHP in content generated:

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

Instead of a here-doc, you can switch back into HTML mode, and then use <?php echo ... ?> within that to insert PHP values.

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