1)PHP文件的构成
PHP文件由HTML和PHP的内容组成,一般形如:
<html>
<body>
...
<?php
...
?>
...
<?php
...
?>
...
</body>
</html>
2)PHP与HTML代码的杂交
例如:
<?php
$name=$_POST['name'];
$passwd=$_POST['passwd'];
if( !isset($name) || !isset($passwd) ) {
?>
<p>html part</p>
<p>html part</p>
<?php
} else if(...) {
...
}
?>
这里的html部分受PHP中的if控制。
3)PHP中include其他HTML或PHP文件
PHP中包含其他PHP文件时,我理解为在include处变成:
?> ...content... <?php
比如:
<!-header.php->
<html><body>
<p>the first line in header.</p>
<?php
echo "the second line in header."."<br/>";
?>
<p>the third line in header.</p>
</body></html>
被添加到:
<!-test.php->
<html><body>
<?php
include 'header.php'
echo "hello world."."<br/>"
?>
</body></html>
其结果就形如:
<!-test.php->
<html><body>
<p>the first line in header.</p>
<?php
echo "the second line in header."."<br/>";
?>
<p>the third line in header.</p>
<?php
echo "hello world."."<br/>"
?>
</body></html>