Here's how it works:
- PHP runs
- PHP outputs stuff
- Stuff gets sent to browser.
It doesn't matter what the "stuff" is. Typically it will be HTML, but it could be an image (using imagecreate
and related functions), it could be JavaScript (not sure why you'd want to do this), or even CSS (even less likely). PHP can output JSON. Heck, I seem to recall reading about PHP functions that would let you generate SWF files!
Once PHP is done running, the browser then receives what it sends and deals with it. The browser doesn't know that PHP had anything to do with it. As far as it's concerned, it is whatever the Content-Type
header says it is.
This is why PHP can generate JavaScript inline (<script>alert(<?php echo 123; ?>);</script>
) but not the other way around. The browser doesn't care, it just sees the result.