Question

I have a div that I want to put one image inside, how could I do something like that:

Javascript:

<script>
    document.getElementById("people").innerHTML =
    document.getElementById("people").innerHTML + "<img src='farmer.gif'>";
</script>

Html:

<html>
  <body>
    <div id = "people"></div>
  </body>
</html>

in PHP? Im so fustrated I can do it in JS but I need to do it in PHP but I don't know how...

Hope you can help me! :D

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top