How to provide dynamic HTML in PHP?

You could use include and ob_get_contents to get the html as string and do some str_replace or preg_replace on that.

Your HTML:

<html>
    <body>
        <img src="https://stackoverflow.com/questions/10533622/{IMAGE_SRC}" width="512" height="512" name="image" />
    </body>
</html>

Your PHP:

ob_start();
include 'your_file.html';
$buffer = ob_get_contents();
ob_end_clean();
$buffer = str_replace("https://stackoverflow.com/questions/10533622/{IMAGE_SRC}", 'your_image.png', $buffer);

print $buffer;

Leave a Comment