1 / 41
文档名称:

php实例.docx

格式:docx   大小:528KB   页数:41页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

php实例.docx

上传人:碎碎念的折木 2022/6/13 文件大小:528 KB

下载得到文件列表

php实例.docx

文档介绍

文档介绍:PHP 简单实例
版本历史
1.文档属性
文件状态
文档
编号
版本


[√] 初稿
[ ] 发布
文档
密级
公开
[ ] 修订
采纳
标准
2.版本历史


日期
版本行验证,则必须借助正则表达式的帮助。
通过preg_match()和 preg_match_all()函数对表单中提交的手机号码和座机号码进行验证, 并返回各自的匹配次数。操作步骤如下:
首先,创建 form 表单,添加表单元素,将电话号码提交到 。然后,编写 PHP 脚本,通过$_POST[]方法获取表单提交的电话号码。最后,通过 preg_match()函数对座机号码惊喜匹配,通过 preg_match_all()函数对手机号码进行匹配。代码如下:
<form id="form1" name="form1" method="post" action="/test/">
<div >
座机号码: <input name="tel" type="text" size="16" />
<input type="submit" name="check_tel" value="提交"/>
</div>
<div>
手机号码:<input name="phone" type="text" "size="16" />
<input type="submit" name="check_phone" value="提交"/>
</div>
<?
$checktel="/^(\d{3}-)(\d{8})$|^(\d{4}-)(\d{7})$|^(\d{4}-)(\d{8})$/;"
//定义验证座机号码的正则表达式
$checkphone="/^13(\\d{9})$|^15(\\d{9})$/"; //定义验证手机号码的正则表达式
2 / 40
if(isset($_POST['check_tel']) && !empty($_POST['check_tel'])){
$counts=preg_match($checktel, $_POST['check_tel']);
if($counts==1){
echo "<script>alert('座机号码格式正确! ');='';</script>;"
}else {
echo "<script>alert('座机号码格式不正确! ');='';</script>;"
}
}
if(isset($_POST['check_phone']) and !empty($_POST['check_phone'])){
$counts=preg_match_all($checkphone,$_POST['check_phone'],$arr);
if($counts==1){
echo "<script>alert('手机号码格式正确! ');='';</script>;"
}else {
echo "<script>alert('手机号码格式不正确! ');='';</script>;"
}
}
?>
</form>
运行效果图:
3 / 40
4 / 40
第二章 用户注册
网站中常需要用户注册功能,主要包括用户名、密码、电子邮箱或者或者安全问题等内
容。
注册界面设计
上图为注册界面 ,用*提醒用户此项为必填内容。在页面的最顶端,用 js 代码获取当前客户端日期和时间显示出来。对于底部验证码的设计,具体请参照第三章验证码设计部分。
<html>
<head>
<title>会员注册</title>
<link rel="stylesheet" type="text/css" href="">
<script src=""></script>
</head>
<body>
<div id="reg">
<div class="dt">
<strong>会员注册</strong><span id="time" class="more"></s