Reputation: 111
In what order does a system executes its code when having multiple programming language? Let's say I have this system with codes arrange like this
|
HTML1 - 1st HTML code here
|
PHP1 - 1st PHP code here
|
HTML2 - 2nd HTML code here
|
PHP2 - 2nd PHP code here
|
HTML3 - 3rd HTML code here
does it read from top to bottom like this:
Execute HTML1 -- PHP1 -- HTML2 -- PHP2 -- HTML3
OR
there is some hierarchy when executing the codes?
Like
Execute first all PHP codes then HTML codes follows?
The purpose of this question is in order for a beginner like me to understand how codes are executed so that I can plan on how my code will flow
Upvotes: 1
Views: 71
Reputation: 522597
The same system rarely interprets PHP and HTML, it does either or.
It's a little hard to guess what exactly you're talking about, but I'm assuming you're talking about a file like this:
<html>
...
<?php echo 'foo'; ?>
<p><?php echo 'bar'; ?></p>
<script type="text/javascript">
alert('baz');
</script>
</html>
In this case, each "language" is handled by a different system entirely.
<?php ?>
snippets (from top to bottom) and completely ignores anything else.*<?php ?>
snippets anymore. It returns whatever PHP spit out after it was done.<script>
snippets are executed by the client's Javascript implementation, if it has such a thing.A visual reminder, taken from https://stackoverflow.com/a/13840431/476:
|
---------->
HTTP request
|
+--------------+ | +--------------+
| | | | |
| browser | | | web server |
| (Javascript) | | | (PHP etc.) |
| | | | |
+--------------+ | +--------------+
|
client side | server side
|
<----------
HTML, CSS, Javascript
|
* By "ignore" I mean it just passes it right through as output, it does not interpret it as PHP code.
Upvotes: 6
Reputation: 1913
Basically it's PHP first and then HTML.
This is because PHP code is executed server-side. It usually operates on some data, generates some HTML markup and then all of it is being sent to the client. When client receives the generated markup then his browser parses and displays it.
Also all of the CSS and JavaScript is executed within the clients browser.
Upvotes: 1