(1)、代码
for ($a=0;$a<10; $a++) {
echo $a,'<br>';
}
(2)、效果:
2、while(循环判断条件){……更新条件;……}或者do {……更新条件……}while(循环判断条件);循环实列:
(1)、代码:
$a=0;
while($a<10) {
echo $a,',';
$a++;
}
$a=0;
do {
echo $a,'<br>';
$a++;
} while($a<0);
(2)、效果:
(1)代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户注册表单</title>
<style>
.login{
width: 400px;
height: 430px;
background-color: #55a532;
margin:0 auto;
padding: 10px;
font-size: 16px;
color: #fffdef;
border-radius: 20px;
}
.login:hover {
box-shadow: 0 0 3px #333333 ;
}
.login > h3 {
width: 100px;
margin: 20px auto;
color: #222222;
}
.login > form {
display: grid;
grid-template-columns: 70px 1fr;
grid-template-rows:repeat(7,40px) ;
place-items: center;
}
.login > form > input {
width: 200px;
height: 25px;
}
.login > form > input:nth-last-of-type(n+3):hover {
box-shadow: 0 0 3px #df5000 inset;
}
.login > form > label {
width: 80px;
height: 25px;
position: relative;
left:60px;
}
.login > form > input:nth-last-of-type(-n+2) {
margin: 15px 0;
width:100px;
height:35px;
border-style: none;
background-color: #ff0000;
color:#fffdef;
position: relative;
left:66px;
}
.login > form > input:nth-last-of-type(-n+2):hover{
background-color: #178CEE;
}
</style>
</head>
<body>
<div class="login">
<h3>新用户注册</h3>
<form action="login_verify.php" method="post" name="sign-in">
<label for="username"><span>用户名:</span></label>
<input type="text" name="username" id="username" autofocus placeholder="请输入你的账号" required>
<label for="pwd1"><span>密 码:</span></label>
<input type="password" name="pwd1" id="pwd1" placeholder="请输入你的密码" required>
<label for="pwd2"><span>密 码:</span></label>
<input type="password" name="pwd2" id="pwd2" placeholder="请再次输入你的密码" required>
<label for="email"><span>邮箱</span></label>
<input type="email" name="email" id="email" placeholder="请输入邮箱" required>
<label for="tel"><span>电话</span></label>
<input type="tel" name="tel" id="tel" placeholder="请输入手机号" required>
<label for="gender"><span>性别</span></label>
<div>
<input type="radio" name="gender" value="1" checked>男
<input type="radio" name="gender" value="2">女
<input type="radio" name="gender" value="0" id="gender" >保密
</div>
<label for="like"><span>兴趣爱好</span></label>
<div>
<input type="checkbox" name="like[]" value="1">html
<input type="checkbox" name="like[]" value="2">css
<input type="checkbox" name="like[]" value="3" checked id="like">php
</div>
<input type="submit" value="注册">
<input type="reset" value="重置">
</form>
</div>
</body>
</html>
<?php
//echo '用户名:',$_POST['username'],'<br>';
//echo '密码:',$_POST['pwd1'],'<br>';
//echo '密码:',$_POST['pwd2'],'<br>';
//echo '邮箱:',$_POST['email'],'<br>';
//echo '手机:',$_POST['tel'],'<br>';
//echo '性别:',$_POST['gender'],'<br>';
//echo '兴趣爱好'.print_r($_POST["like"],true),'<br>';
//
//echo '<pre>' . print_r($_POST, true) . '</pre>';
//echo '请求判断类型'.$_SERVER['REQUEST_METHOD'].'<br>';
#验证request类型
if ($_SERVER['REQUEST_METHOD']=='POST') {
if (!empty($_POST['username'])) {
echo $_POST['username'];
};
// $_POST['pwd1']==$_POST['pwd2'] ? $pwd=$_POST['pwd1']: print_r('密码不一致');
if (!empty($_POST['username'])) $username=$_POST['username'];
if (!empty($_POST['email'])) $email=$_POST['email'];
if (!empty($_POST['tel'])) $tel=$_POST['tel'];
if (!empty($_POST['gender'])) $gender=$_POST['gender'];
if (!empty($_POST['like'])) $likes=$_POST['like'];
if ( $_POST['pwd1']==$_POST['pwd2']) {
$pwd=$_POST['pwd1'];
} else {
exit('<script>alert("二次密码不一致");history.back();</script>');
}
$users_date=compact('username','pwd','email','tel','gender','likes');
echo '<pre>'.print_r($users_date,true).'</pre>';
echo '<script>alert("注册成功");</script>';
} else {
exit("请求方式不正确");
};
(1)、字符串操作函数:strlen();
和 mb_strlen();
分别计算字符长度和汉字长度;
trim();ltrim();rtrim();剔除字符串,两端、左、右指定字符,默认空格;
(2)、数组:count();
计算数组元素个数; key();``、current()
;获取数组的当前元素的键和值
(3)、随机返回数值:mt_rand();
(range();
返回数组);
(4)、指针函数:reset();
重置指针到数组开始位置
next();
指针移动到下一个元素,直至移出数组
prev();
指针移动到上一个元素,直至移出数组
end();
指针移动到最后一个元素;
(1)input类型(type):text\tel\email\radio\checkbox\password\file\hidden\submit\reset\button\number\url\color\date\search\等等
(2)input属性:name\value\placeholder\autofocus\required\disabled\readonly
placeholder:输入框提示内容
autofocus:页面加载时自动获得焦点
required:必填\或必选项
(3)、border-radius:2px;
设置边框圆角;box-shadow:0 0 3px 3px #ff0000 inset;
设置box阴影
(4)、nth-child(n+2);数字表示起始值,n/-n:自动递增,直至表达式表示的数量结束。
(1)、超全局:$_POST();``$_GET();``$_REQUEST();
$_SERVER('REQUEST_METHOD');
返回值为大写POST或者GET;
(2)、isset();
和 empty();
区别:
empty();
判断 空字符串, 0, null, false;
isset();
检查请求变量是否设置, 并且值不能为NULL,用在设置请求变量默认值;
(3)、分支语句简化:
1、if(条件)语句;
2、三元运算符:(条件)?语句:语句;语句中不能使用echo输出;
(4)、密码加密方式:md5();
32位随机字符串;sha1();
40位随机字符串;
(5)js:
弹窗函数:<script>alert("二次密码不一致");</script>
;
返回上页函数:<script>history.back();</script>