This is the amusing irony of PHP. It's a programming language designed to make generating HTML and interfacing with the web easy, but it's actually very hard (compared to other languages) to do either of these things.
I don't think anyone wanted generating HTML to be easy with PHP; the original point was that your little script was embedded in the HTML. The document was the primary thing, and the code was just for this or that specific purpose.