PHP笔记03
PHP表单
获取表单数据
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<!--提交表单到bd.php文件-->
<form action="bd.php" method="post">
请输入姓名:<input type="text" name="uname" value="yourname" /><br>
请输入年龄:<input type="number" name="uage" max="120" min="1" value="20" /><br>
<input type="submit" />
</form>
</body>
</html>
<?php
echo "你的名字是:",$_POST['uname'],"<br>";
echo "你今年:",$_POST['uage'],"岁";
?>
获取下拉菜单数据
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="bd.php" method="post">
请输入姓名:<input type="text" name="uname" value="小明"/><br>
请输入年龄:<input type="number" name="uage" max="120" min="1" value="20" /><br>
<select name="xlcd">
<option value ="">请选择你的性别</option>
<option value ="男">男</option>
<option value ="女">女</option>
<option value ="不知道">不知道</option>
</select><br>
<input type="submit" />
</form>
</body>
</html>
<?php
echo "你的名字是:",$_POST['uname'],"<br>";
echo "你今年:",$_POST['uage'],"岁<br>";
echo "你的性别是:",$_POST['xlcd'],"。";
?>
获取下拉多选数据
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="bd.php" method="post">
请输入姓名:<input type="text" name="uname" value="小明"/><br>
请输入年龄:<input type="number" name="uage" max="120" min="1" value="20" /><br>
<select name="xlcd">
<option value ="男">男</option>
<option value ="女">女</option>
<option value ="不知道">不知道</option>
</select><br>
<select multiple="multiple" name="like[]">
<option value ="">请选择你喜欢的食物</option>
<option value ="苹果">苹果</option>
<option value ="香蕉">香蕉</option>
<option value ="橘子">橘子</option>
<option value ="粑粑">粑粑</option>
</select><br>
<input type="submit" />
</form>
</body>
</html>
<?php
echo "你的名字是:",$_POST['uname'],"<br>";
echo "你今年:",$_POST['uage'],"岁<br>";
echo "你的性别是:",$_POST['xlcd'],"。<br>";
echo "你喜欢吃:";
$x=$_POST['like'];
foreach($x as $i){
echo $i;
}
echo "...<br>";
?>
获取单选按钮值
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="bd.php" method="post">
请输入姓名:<input type="text" name="uname" value="小明"/><br>
请输入年龄:<input type="number" name="uage" max="120" min="1" value="20" /><br>
你的性别:
<select name="xlcd">
<option value ="男">男</option>
<option value ="女">女</option>
<option value ="不知道">不知道</option>
</select><br>
你喜欢吃什么:
<select multiple="multiple" name="like[]">
<option value ="苹果">苹果 </option>
<option value ="香蕉">香蕉</option>
<option value ="橘子">橘子</option>
<option value ="粑粑">粑粑</option>
</select><br>
现在时间是:
<input type="radio" name="ap" id="" value="上午" />上午
<input type="radio" name="ap" id="" value="下午" />下午<br />
<input type="submit" />
</form>
</body>
</html>
<?php
echo "你的名字是:",$_POST['uname'],"<br>";
echo "你今年:",$_POST['uage'],"岁<br>";
echo "你的性别是:",$_POST['xlcd'],"。<br>";
echo "你喜欢吃:";
$x=$_POST['like'];
foreach($x as $i){
echo $i;
}
echo "...<br>";
echo "现在时间是:",$_POST['ap'],"。<br>";
?>
获取CheckBox复选框
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="bd.php" method="post">
请输入姓名:<input type="text" name="uname" value="小明"/><br>
请输入年龄:<input type="number" name="uage" max="120" min="1" value="20" /><br>
你的性别:
<select name="xlcd">
<option value ="男">男</option>
<option value ="女">女</option>
<option value ="不知道">不知道</option>
</select><br>
你喜欢吃什么:
<select multiple="multiple" name="like[]">
<option value ="苹果">苹果 </option>
<option value ="香蕉">香蕉</option>
<option value ="橘子">橘子</option>
<option value ="粑粑">粑粑</option>
</select><br>
现在时间是:
<input type="radio" name="ap" id="" value="上午" />上午
<input type="radio" name="ap" id="" value="下午" />下午<br />
以下哪些地名位于江苏省:
<input type="checkbox" name="dl[]" id="" value="宿迁" />宿迁
<input type="checkbox" name="dl[]" id="" value="淮安" />淮安
<input type="checkbox" name="dl[]" id="" value="南京" />南京
<input type="checkbox" name="dl[]" id="" value="合肥" />合肥
<br />
<input type="submit" />
</form>
</body>
</html>
<?php
echo "你的名字是:",$_POST['uname'],"<br>";
echo "你今年:",$_POST['uage'],"岁<br>";
echo "你的性别是:",$_POST['xlcd'],"。<br>";
echo "你喜欢吃:";
foreach($_POST['like'] as $i){
echo $i;
}
echo "...<br>";
echo "现在时间是:",$_POST['ap'],"。<br>";
echo "这些城市是江苏省的:";
foreach($_POST['dl'] as $i)
echo $i," ";
echo "。<br>";
?>
include和require
- require发生错误立即停止
- include发生错误不停止只警告
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<html>
<body>
include测试:
<?php
include "bd.php";
echo "<br>";
test();
echo "<br>";
echo $test;
?>
</body>
</html>
</body>
</html>
<?php
echo "<br>include导入成功!";
$test="变量输出成功!";
function test(){
echo "函数使用成功!";
}
?>
PHP文件处理
- fopen打开
- fclose关闭
- feof检测文件末尾
- fgets逐行读取
- fgetc逐字读取