BartB wrote:Can one specify the load order of php and html?
I have a php3 file containing html parts and php parts. What I want is that all of the html are loaded before the php starts to work.
It's hard to know quite what you mean. From the perspective of the interpreter, the script is "loaded" all at once. It is interpreted (processed, executed, whatever), however, in linear order, from top to bottom. So if your page looks like this:
- Code: Select all
/* ... some PHP code ... */
.. the interpreter will pass the first two lines (because they're not inside PHP tags) to the output handler (e.g. the server and, in turn, to the browser) , then it will execute whatever is between the PHP tags and send its output, if any, to the server, and then it will pass the last two lines. It's important to remember that the browser never sees anything until after
it has been handled by PHP, and PHP will always handle your script from top to bottom. That is, it'll handle your script in exactly the order it's written. If you have HTML before PHP, it'll pass the HTML before it interprets the PHP. If you have PHP before HTML, it'll interpret the PHP before it passes the HTML. And if you have PHP in the middle of two blocks of HTML, it'll pass the first block of HTML, interpret the PHP, and then pass the second block of HTML.
If, for some reason, you want to pass only HTML at the beginning of your script, and not interpret any PHP until the very end once all HTML output is sent, you must put all of the PHP at the end of the script:
- Code: Select all
... your HTML body ...
/* some PHP code.. */
But in the case above, once the HTML is sent there's no way to "go back" and have PHP add content in the middle, because it's already been sent to the server. (Well, unless you're using output buffering, but except in a very few cases, that's pretty much just faking it.)
I'd be very interested to know exactly what you're trying to do here and why, because it sounds like a) you're a little unclear on exactly how the HTTP model works, and b) there's probably a far easier way to do whatever it is you're after.