<code><html> <head> <meta charset="utf-8"> <title>展示学生资料</title> </head> <body> <?php $name="王六"; ?> <table> <tr> <td>姓名</td> <td><?php echo $name;?></td> </tr> </table> </body> </html> </code>
The above program is saved as test.php and opened with a browser, and the displayed result is as follows
Name Wang Liu
When the above program is saved as test.html, opened with a browser, the displayed result is as follows
Name
The php in it is not parsed ?
Same content, different file types, why are there different results?
<code><html> <head> <meta charset="utf-8"> <title>展示学生资料</title> </head> <body> <?php $name="王六"; ?> <table> <tr> <td>姓名</td> <td><?php echo $name;?></td> </tr> </table> </body> </html> </code>
The above program is saved as test.php and opened with a browser, and the displayed result is as follows
Name Wang Liu
When the above program is saved as test.html, opened with a browser, the displayed result is as follows
Name
The php in it is not parsed ?
Same content, different file types, why are there different results?
Save it as a php file. During parsing, the php engine will parse the php related code. $name will be read by the browser and saved as html. The php code will be automatically ignored because html does not recognize the php code. So there is no value of $name in the end
Suffix identification problem. For PHP, the browser needs to cooperate with the server environment, and the two are processed together. If it is a suffix such as .html, the browser will think that it is a static file in itself and has nothing to do with the server, etc., so it will parse it by itself (actually It is ignored by php and does not reach php to parse). Generally speaking, only php files can contain html code, and cannot be used the other way around
html files will not parse PHP