Home > Backend Development > PHP Tutorial > The html file and the php file have the same content, but the opening effect is different?

The html file and the php file have the same content, but the opening effect is different?

WBOY
Release: 2016-10-18 08:55:59
Original
1649 people have browsed it

<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>
Copy after login
Copy after login

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?

Reply content:

<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>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template