我有点困惑如何下面的代码工作.在我的脑海中,我想象每个php块作为一个整体执行并呈现为HTML.事实上,第一个块有一个不完整的悬挂支架不能很好地与我想象PHP工作.当PHP模块到达PHP结束标记时,它会做什么?PHP标记内的代码如何影响PHP标记之外的明文输出,即只是有条件地输出表单?
我本以为要完成下面的工作,你实际上必须使用echo语句来有条件地回显表单.
<html>
<head></head>
<body>
<?php
/* if the "submit" variable does not exist, the form has not been submitted - display initial page */
if (!isset($_POST['submit'])) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Enter your age: <input name="age" size="2">
<input type="submit" name="submit" value="Go">
</form>
<?php
}
else {
/* if the "submit" variable exists, the form has been submitted - look for and process form data */
// display result
$age = $_POST['age'];
if ($age >= 21) {
echo 'Come on in, we have alcohol and music awaiting you!';
}
else {
echo 'You're too young for this club, come back when you're a little older';
}
}
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
325 次 |
| 最近记录: |