Fast VERY DIRTY WAY:
do ob_start();
at the first line of the script
do echo "<div>%imag1flag%</div>";
do $content = ob_get_clean();
at the end of the script
change contnet with $content = str_replace('%imag1flag%','<img ...>',$content);
But wonder why you didnt paste the image in the first place eg:
echo "<div><img ...></div>";
Keep in Mind Javascript is Statefull
PHP is NOT Statefull
.
When u got that, maybe you will laugth about your Question ;)
Bye!