PHP text in PHP and HTML code who executes who first?

Source: Internet
Author: User

PHP text in PHP and HTML code who executes who first?For example, PHP contains an HTML text, and then the HTML code contains a PHP text, according to who first contains who was executed by the server, that is, execute PHP first, then execute the inside HTML, and then execute the HTML inside the PHP?Diligent Fanhao | Browse 1322 times 2013-10-13 21:22 Best Answer
Execute PHP code First, PHP and HTML mixed when you must have encountered the following situation:
<?php if (true) {?>
<div>true</div>
<?php}else{ ?>
<div>false</div>
<?php}?>
The result of the above code is that the browser is displaying <div>true</div>
If you do HTML first then you will find that the logic of PHP will not take effect.
So first executes the PHP, and the PHP file in the HTML code, the program will be implicitly considered a string by PHP output. The final rendering effect of the above code would be the following code if it were all replaced by PHP:
<?php if (true) {
Echo ' <div>true</div> ';
}else{
Echo ' <div>false</div> ';
}
?>
Ask
A bit faint, just want to ask, PHP text in the PHP code contains HTML code, HTML code, and then the PHP code, is to execute the first PHP code in order to execute the inside of the HTML code, and then execute the HTML inside the PHP code? Or do I run out of PHP code, and then go back and execute the HTML code, or PHP is done directly to the browser to throw HTML code to execute? It's a little verbose, but I hope the great God helps.
Chase Answer
First, the PHP code will be executed from top to bottom. Execute line by row, such as 2 files, A and B, respectively:
A file code:
<?php
echo "Include "b.php";
echo "a.php";
?>
B File Code:
<?php
echo "b.php";
?>
The final execution effect is:
<?php
echo "echo "b.php";
echo "a.php";
?>
I don't know if that means you understand?
There is the HTML is not executed, the final PHP program will be returned after the HTML code. The HTML code that the above code will eventually return to the browser is:
Then the browser will parse the HTML code returned by PHP!
Ask
So, I confirm my understanding, you can see. That is, in the PHP engine only execute PHP code (do not execute HTML code), the PHP code is finished, the parsed PHP code, this should be the HTML code, along with the original HTML code to return to the browser, the browser then in the order of HTML execution! Yes, great God.
Chase Answer
Well, yes! You can understand this!

PHP text in PHP and HTML code who executes who first?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.