03_php_基本案例 ...

本文介绍了一个简单的PHP程序,用于判断输入的数字是否为偶数,并提供了一个判断输入年份是否为闰年的功能。通过表单提交数字或年份,程序将返回相应的判断结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >





注意计算机获取的都是字符串



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
//isset为真表示提交了按钮
if(isset($_POST['button']))
{
$num=$_POST['num'];

if(is_numeric($num))
{
$num=$num+0;
if(is_int($num))
{
if($num%2==0)
{
echo $num.'是偶数';
}
else
{
echo "{$num}是偶数";
}

}
else
{
echo "{$num} 不是整数";
}
}
else
{
echo "{$num} 不是数字";
}

}
?>
<form id="form1" name="form1" method="post" action="">
<table width="500" border="1" align="center">
<tr>
<th colspan="2">请输入数字</th>
</tr>
<tr>
<td width="240">请输入一个数</td>
<td width="244"><input type="text" name="num" id="num" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>



判断瑞年

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
if(isset($_POST['button']))
{
$year=$_POST['year'];
if(is_numeric($year))
{
$year+=0;
if(is_int($year))
{
if($year>0)
{
if($year%4==0 && $year%100!=0 || $year%400==0)
{
echo "{$year} 是瑞年";
}
else
{
echo $year.' 不是瑞年';
}
}
else
{
echo $year.' 不是负数';
}
}
else
{
echo $year.' 不是整数';
}
}
else
{
echo $year.' 不是数字';
}
}
?>

<form id="form1" name="form1" method="post" action="">
<table width="500" border="1" align="center">
<tr>
<td colspan="2" align="center">判断瑞年</td>
</tr>
<tr>
<td>请输入年份</td>
<td align="center"><input type="text" name="year" id="year" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form>
</body>
</html>


多分支
if(条件)
{
}
elseif(条件)
{
}
elseif(条件)
{
}

else
{
}

for循环
for(;;)
{
//死循环
}

foreach 遍历数组
foreach(数组 as 值变量)






函数
function

function 函数名(参数){
//函数体
[return]
}


















转载于:https://www.cnblogs.com/szm2019/p/7140911.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值