地包天什么意思| 口臭严重吃什么药好得快| 种小麦用什么肥料好| 花椰菜是什么菜| 情感障碍是什么意思| p波增宽什么意思| 成龙真名叫什么名字| 书中自有颜如玉是什么意思| 畸胎瘤是什么病严重吗| 薄荷叶泡水喝有什么功效和作用| 屁多且臭是什么原因| 青梅什么季节成熟| bps是什么意思| 孩子不长个子是什么原因| 釜底抽薪是什么计| 三点水加个及念什么| 麻是什么原因| 坐围是什么| 眼屎多吃什么药| 大张伟原名叫什么| 越南三宝是什么| 同房有什么姿势| 12月21号是什么星座| 什么叫变应性鼻炎| 颈部淋巴结肿大吃什么药| 眼睑痉挛挂什么科| 40年什么婚| 新生儿黄疸是什么原因引起的| 蒸米饭时加什么好吃| wwe是什么意思| 左手小手指麻木是什么原因引起的| 五福是什么| 浙江大学校长什么级别| 乳头疼吃什么药| 90年出生属什么生肖| 胸前有痣代表什么意思| 伤官见官是什么意思| 邻家女孩什么意思| 满身红点是什么病| 什么地唱歌| 耳鸣和脑鸣有什么区别| 无常是什么意思| 吹弹可破的意思是什么| 怀孕为什么会肚子痛| 什么不可什么| 筷子在古代叫什么| nc是什么意思| 春天的雨像什么| 人为什么要生孩子| 荆芥是什么| 病人是什么生肖| 有齿痕吃什么药| 手脚肿胀是什么原因引起的| 什么耳机比较好| 睡觉小腿抽筋是什么原因| 处子之身是什么意思| 床上有横梁有什么害处| 乙肝五项145阳性是什么意思| 隐匿是什么意思| 为什么拉屎会出血| 发烧看什么科室| 孕妇梦见鬼是什么预兆| 大腿后侧肌肉叫什么| 临床医生是什么意思| 五花八门是什么生肖| 5月9号什么星座| 在圣是什么生肖| ahc是韩国什么档次| 发什么大成语| 乳腺增生什么意思| yeezy是什么牌子| 口酸吃什么药| fda是什么意思| 嘴馋是什么意思| 楚怀王和芈月什么关系| 京东自营店是什么意思| molly什么意思| 原研药是什么意思| 感知力是什么意思| 什么是散射光| 伴侣是什么意思| 左舌根疼痛是什么情况| 五十八岁属什么生肖| 我宣你 是什么意思| 内痔用什么药| 0是什么数| 梦见被熊追是什么意思| kpa什么意思| 什么是大三阳| 脚心痒是什么原因引起的| 心理活动是什么意思| 吃什么补血快效果好| 霉菌是什么引起的| 梦见自己生二胎是什么意思| 广州和广东有什么区别| pvs是什么意思| bag是什么意思| 可喜可贺是什么意思| 邵字五行属什么| 三唑仑是什么| ab制是什么意思| 什么什么的眼睛| 来月经不能吃什么水果| 嗓子疼吃什么水果好得快| 祖庭是什么意思| 慧眼识珠是什么意思| 血蛋白低是什么原因| 心率过快吃什么药好| pony是什么意思| 封顶是什么意思| 维生素d补什么| 六月二十一是什么日子| 负罪感什么意思| 尿酸高吃什么降的快| 健身吃什么长肌肉最快| 强直性脊柱炎看什么科| 笑面虎比喻什么样的人| 鸽子单眼伤风用什么药| 吃什么不掉头发| 鳄鱼为什么流眼泪| 屠苏指的是什么| nu11是什么意思| 爬是什么结构| 心脏做什么检查最准确| 吃了就吐是什么原因| 杜比全景声是什么意思| 减肥最快的方法是什么| 做生化是检查什么的| 学考成绩什么时候公布| 声声慢是什么意思| 十月7号是什么星座| 减肥早上吃什么比较好| 为什么月经期有性冲动| 吃什么补津液| avia是什么牌子| 便秘喝什么| 全身无力是什么原因| hp代表什么意思| 发冷发热是什么原因| icd医学上是什么意思| 2004是什么年| 送荷花的寓意是什么| 阿司匹林主要治什么病| 腋窝出汗是什么原因| 小腿肿胀是什么原因引起的| 儿童流鼻血挂什么科| 小孩咳嗽是什么原因引起的| 脾胃虚寒能吃什么水果| 鸡精吃多了有什么危害| 什么情况下做冠脉ct| 睡觉容易惊醒是什么原因| 胆汁反流吃什么药| 什么的青草| 梵克雅宝为什么那么贵| 好嘞是什么意思| 什么是肺部腺性肿瘤| 钴对人体有什么伤害| 狗和什么属相相冲| 月经量少是什么原因啊| 凝血四项能查出什么病| 排卵期什么意思| 嘴唇颜色深是什么原因| geneva是什么牌子手表| 134是什么意思| VH是什么品牌| 87年的兔是什么命| 痛风能吃什么| 两肺纹理增重什么意思| 脚后跟疼是什么情况| 什么的寒风| 银联是什么| 中国美食有什么| 肽是什么东西| 做梦捡到钱是什么预兆| 五合是什么意思| 四肢无力是什么原因| 就诊卡号是什么| 空窗期是什么| 辩证法是什么| 南乳是什么| 与世隔绝的绝是什么意思| 空白是什么意思| 什么是商k| 九月一日是什么星座| 口苦口干吃什么药好| 巾帼是指什么| 脖子疼是什么原因引起的| 女性腰肌劳损吃什么药| 碳酸钠是什么东西| 王的五行属性是什么| 腋窝淹了用什么药| 左耳朵发热代表什么预兆| 排卵期同房后要注意什么| 百无一用是什么意思| 腐竹是什么做的| 梦到自己老公出轨是什么意思| 咽炎用什么药好| 抖s是什么意思| 女人阴部黑是什么原因| 吹空调咳嗽吃什么药| 治疗脚气用什么药| 八月五号是什么星座| 哨兵是什么意思| 乳房上长黑色的斑点是什么原因| 闪光眼是什么症状| 痤疮是什么东西| 高湛为什么帮梅长苏| 昏什么昏什么| 康复治疗学主要学什么| 老鸨什么意思| 梦魇是什么原因造成的| 精神病的前兆是什么| 213什么星座| 拿铁是什么咖啡| 甜蜜素是什么| 胸腺癌早期有什么症状| 视而不见的意思是什么| 马甲是什么意思?| 毛孔粗大是什么原因引起的| 禹五行属什么| 身体发冷是什么原因| 器质性心脏病是什么意思| 维生素d3什么牌子好| 圣诞节送女生什么礼物好| 背德感是什么意思| 角头是什么意思| 为什么阴道会排气| 喉咙痛吃什么药好得快| 夹页念什么| 工字五行属什么| 红粉是什么意思| 皮实是什么意思| 牛肉馅饺子配什么菜| 二便是什么意思| 早餐吃什么最健康| 耳后有痣代表什么| 古字五行属什么| 一只什么| 相与是什么意思| 乌龟能吃什么| 外公的妈妈叫什么| 支原体阳性是什么病| 上海为什么叫申城| 梦见自行车是什么意思| 扁平足为什么不能当兵| 白细胞减少是什么原因| 突然消瘦是什么原因| 过敏可以吃什么| 吃什么补钾最快最好| 冷酷是什么意思| 为什么下雨会打雷| 女人肾虚吃什么药调理| 榨菜是什么菜做的| 心慌手抖是什么原因| 一什么饼干| 一龙一什么| 本科生是什么意思| 实相是什么意思| 大头鱼吃什么食物| 阴囊是什么| 五行什么生水| 吟诗作赋是什么意思| 一九八七年属什么生肖| 生精补精吃什么药最快| 百度
PHP Form - Veri...LOGIN

健康中国?2016中国健康管理与促进大会在青岛开幕

百度 一个健全的社会,总是需要这样一个群体去担当这部分的社会职能。

When it comes to verification, we need to know the regular expression:

Regular expression

Regular expression is a method of describing a text rule. It is not an exact match, but a fuzzy match through some specific symbols

In PHP, we use the preg_match function to Perform regular expression matching. One parameter is our regular expression rule, and the second parameter is the text to be checked

preg_match (string $regular, string $character String[, array &$result] )

Function: Match $string variable based on $regular variable. If it exists, return the number of matches and put the matched results into the $result variable. If no result is found, 0 is returned.

^ indicates the beginning; $ indicates the end

Let’s take a look at the code:

<?php
 header("Content-type:text/html;charset=utf-8");    //设置编码
 $str = 'date20150121';
 if (preg_match('/^date/', $str)) {
     echo '匹配成功';
 } else {
     echo '匹配失败';
 }
 ?>

The above code matches numbers starting with date. The matching results are as follows:

Matching successful


preg_matchedeThe third parameter is matched Content, usually we will pass an empty array in, because it is a call by address. After the matching is completed, the specific matching content will be obtained in the array

Example

<?php
 header("Content-type:text/html;charset=utf-8");    //设置编码
 $str = 'date20150121';
 if (preg_match('/^date/', $str,$mat)) {
     print_r($mat);
 } else {
     echo '匹配失败';
 }
 ?>

Program running result:

Array ( [0] => date )


In regular expressions, letters are represented by \w and numbers are represented by \d (\D represents non-digits)

? + means one or more

? * means 0 or more

? ? means there or not

? {n} represents the specific number

? {m, n} represents more than m and less than n

Just like the following :

<?php
 header("Content-type:text/html;charset=utf-8");    //设置编码
 $name = "zhang"; // wang zhu hu ma tan
 
 if (preg_match('/an|hu/', $name, $arr)) {
     print_r($arr);
 } else {
     echo '匹配失败';
 }
 ?>

Program running result:

Array ( [0] => an )


Using or conditions can be used to match strings. If it is just a single letter or character, you can use a range representation

Use [] Indicates the value range of a character

'/[a0\.]/' can match any string containing a or 0 or .

In addition, regular expressions can also be used - To represent a set of ranges

? [a-z] represents any one of the 26 lowercase letters

? [A-Z] represents an uppercase letter

? [0-9 ] represents a decimal number

Now that we know so much, let’s look at using regular expressions to match the content of the form.


PHP - Validation Name

The following code will detect whether the name field contains letters and spaces in a simple way. If the name field value is illegal, an error message will be output:

$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z]*$/",$name)) {
$nameErr = "Only letters and spaces allowed";
}


##PHP - Verification Email

Rules: The email name can be any character consisting of letters, numbers, underscores and dots; the email must contain the @ symbol, and the following text is processed according to domain name rules

The following code will check whether the e-mail address is legal in a simple way. If the e-mail address is illegal, an error message will be output:

$email = test_input($_POST["email"]);

if (!preg_match("/^ [a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/",$email)) {
$emailErr = "Invalid email format!";
}


PHP - Verification URL

The following code will check whether the URL address is legal (the following regular expression operation URL contains dashes: "-"). If the URL address is illegal, an error message will be output:

$website = test_input($_POST["website"]);

if (!preg_match("/\b(?:(?:http?|ftp):\/\/|www\.)[-a-z0- 9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%
=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
}

We will now combine the knowledge we learned above to verify the data in our form.

<!DOCTYPE html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>PHP中文网</title>
 </head>
 
 <style>
     .error {color: #FF0000;}
 </style>
 <body>
 <?php
 // 定义变量并设置为空值
 $nameErr = $emailErr = $genderErr = $websiteErr = "";
 $name = $email = $gender = $comment = $website = "";
 
 if ($_SERVER["REQUEST_METHOD"] == "POST") {
     if (empty($_POST["name"])) {
         $nameErr = "姓名是必填的";
     } else {
         $name = test_input($_POST["name"]);
         // 检查姓名是否包含字母和空白字符
         if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
             $nameErr = "只允许字母和空格";
         }
     }
 
     if (empty($_POST["email"])) {
         $emailErr = "电邮是必填的";
     } else {
         $email = test_input($_POST["email"]);
         // 检查电子邮件地址语法是否有效
         if (!preg_match("/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/",$email)) {
             $emailErr = "无效的 email 格式";
         }
     }
 
     if (empty($_POST["website"])) {
         $website = "";
     } else {
         $website = test_input($_POST["website"]);
         // 检查 URL 地址语法是否有效(正则表达式也允许 URL 中的斜杠)
         if (!preg_match("/\b(?:(?:http?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
             $websiteErr = "无效的 URL";
         }
     }
 
     if (empty($_POST["comment"])) {
         $comment = "";
     } else {
         $comment = test_input($_POST["comment"]);
     }
 
     if (empty($_POST["gender"])) {
         $genderErr = "性别是必选的";
     } else {
         $gender = test_input($_POST["gender"]);
     }
 }
 
 function test_input($data) {
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
 }
 ?>
 
 <h2>PHP 验证实例</h2>
 <p><span class="error">* 必需的字段</span></p>
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
     姓名:<input type="text" name="name">
     <span class="error">* <?php echo $nameErr;?></span>
     <br><br>
     邮箱:<input type="text" name="email">
     <span class="error">* <?php echo $emailErr;?></span>
     <br><br>
     网址:<input type="text" name="website">
     <span class="error"><?php echo $websiteErr;?></span>
     <br><br>
     评论:<textarea name="comment" rows="5" cols="40"></textarea>
     <br><br>
     性别:
     <input type="radio" name="gender" value="female">女性
     <input type="radio" name="gender" value="male">男性
     <span class="error">* <?php echo $genderErr;?></span>
     <br><br>
     <input type="submit" name="submit" value="提交">
 </form>
 
 <?php
 echo "<h2>您的输入:</h2>";
 echo $name;
 echo "<br>";
 echo $email;
 echo "<br>";
 echo $website;
 echo "<br>";
 echo $comment;
 echo "<br>";
 echo $gender;
 ?>
 
 </body>
 </html>

If we don’t fill in the rules according to the rules we wrote above, the following prompt will appear:

0.png

If the information you enter is correct, it will be verified.

You can also use regular expressions to match mobile phone numbers. Think about the rules of mobile phone numbers.


Next Section

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>PHP中文网</title> </head> <style> .error {color: #FF0000;} </style> <body> <?php // 定义变量并设置为空值 $nameErr = $emailErr = $genderErr = $websiteErr = ""; $name = $email = $gender = $comment = $website = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "姓名是必填的"; } else { $name = test_input($_POST["name"]); // 检查姓名是否包含字母和空白字符 if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "只允许字母和空格"; } } if (empty($_POST["email"])) { $emailErr = "电邮是必填的"; } else { $email = test_input($_POST["email"]); // 检查电子邮件地址语法是否有效 if (!preg_match("/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/",$email)) { $emailErr = "无效的 email 格式"; } } if (empty($_POST["website"])) { $website = ""; } else { $website = test_input($_POST["website"]); // 检查 URL 地址语法是否有效(正则表达式也允许 URL 中的斜杠) if (!preg_match("/\b(?:(?:http?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) { $websiteErr = "无效的 URL"; } } if (empty($_POST["comment"])) { $comment = ""; } else { $comment = test_input($_POST["comment"]); } if (empty($_POST["gender"])) { $genderErr = "性别是必选的"; } else { $gender = test_input($_POST["gender"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <h2>PHP 验证实例</h2> <p><span class="error">* 必需的字段</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 姓名:<input type="text" name="name"> <span class="error">* <?php echo $nameErr;?></span> <br><br> 邮箱:<input type="text" name="email"> <span class="error">* <?php echo $emailErr;?></span> <br><br> 网址:<input type="text" name="website"> <span class="error"><?php echo $websiteErr;?></span> <br><br> 评论:<textarea name="comment" rows="5" cols="40"></textarea> <br><br> 性别: <input type="radio" name="gender" value="female">女性 <input type="radio" name="gender" value="male">男性 <span class="error">* <?php echo $genderErr;?></span> <br><br> <input type="submit" name="submit" value="提交"> </form> <?php echo "<h2>您的输入:</h2>"; echo $name; echo "<br>"; echo $email; echo "<br>"; echo $website; echo "<br>"; echo $comment; echo "<br>"; echo $gender; ?> </body> </html>
submitReset Code
ChapterCourseware
空杯是什么意思 小便尿道刺痛吃什么药 胃不好吃什么养胃水果 卷腹是什么 色素沉着有什么办法可以去除
水猴子长什么样 唐僧的袈裟叫什么 睾丸积液吃什么药 蜜蜂的尾巴有什么作用 肾结晶是什么意思
强高是什么意思 夜里睡觉手麻是什么原因 疱疹用什么药最好 不苟言笑的苟是什么意思 上火喝什么茶效果最好
白露是什么季节的节气 豹子是什么牌子 什么发什么颜 左眼跳什么右眼跳什么 长期低血糖对人体有什么危害
魏大勋和李沁什么关系hcv9jop6ns8r.cn 天秤座和什么座最配adwl56.com 小孩心跳快是什么原因hcv9jop5ns1r.cn 包裹是什么意思hcv8jop9ns2r.cn 丝状疣是什么样子图片hcv9jop6ns1r.cn
河蚌为什么没人吃hcv8jop9ns5r.cn 茉莉什么时候开花hcv8jop9ns6r.cn 小孩肠胃感冒吃什么药hcv8jop3ns7r.cn 蹭饭是什么意思hcv8jop4ns8r.cn 蚕豆病是什么hcv7jop6ns4r.cn
宾格是什么hcv8jop3ns1r.cn 复诊是什么意思huizhijixie.com 指甲黄是什么原因hcv7jop5ns1r.cn 猝死是什么原因造成的hcv8jop8ns3r.cn 喝什么茶对身体好hcv7jop4ns7r.cn
什么工作赚钱gysmod.com 日皮是什么意思sanhestory.com 怕什么hcv9jop3ns6r.cn 燕窝是什么做的hcv7jop7ns3r.cn 咽颊炎吃什么药hcv8jop1ns9r.cn
百度