[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 [color=rgb(185, 189, 182) !important][size=1em]7 [color=rgb(185, 189, 182) !important][size=1em]8 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$email = "test@ansoncheung.tk"; [color=rgb(185, 189, 182) !important][size=1em]if [color=rgb(185, 189, 182) !important][size=1em](preg_match('/^[^09][azAZ09_]+([.][azAZ09_]+)[@][azAZ09_]+([.][azAZ09_]+)[.][azAZ]{2,4}$/',$email)) [color=rgb(185, 189, 182) !important][size=1em]{ [color=rgb(185, 189, 182) !important][size=1em]echo "Your email is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong email address format"; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]if (filter_var('test+email@ansoncheung', FILTER_VALIDATE_EMAIL)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your email is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong email address format."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$username = "user_name12"; [color=rgb(185, 189, 182) !important][size=1em]if (preg_match('/^[az\d_]{5,20}$/i', $username)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your username is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong username format."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$phone = "(021)4232323"; [color=rgb(185, 189, 182) !important][size=1em]if (preg_match('/\(?\d{3}\)?[\s.]?\d{3}[\s.]\d{4}/x', $phone)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your phone number is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong phone number."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 [color=rgb(185, 189, 182) !important][size=1em]7 [color=rgb(185, 189, 182) !important][size=1em]8 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$IP = "198.168.1.78"; [color=rgb(185, 189, 182) !important][size=1em]if [color=rgb(185, 189, 182) !important][size=1em](preg_match('/^(([19]?[09]|1[09]{2}|2[04][09]|25[05]).){3}([19]?[09]|1[09]{2}|2[04][09]|25[05])$/',$IP)) [color=rgb(185, 189, 182) !important][size=1em]{ [color=rgb(185, 189, 182) !important][size=1em]echo "Your IP address is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong IP address."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$zipcode = "123455434"; [color=rgb(185, 189, 182) !important][size=1em]if (preg_match("/^([09]{5})([09]{4})?$/i",$zipcode)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your Zip code is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong Zip code."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$ssn = "333232329"; [color=rgb(185, 189, 182) !important][size=1em]if (preg_match('/^[\d]{3}[\d]{2}[\d]{4}$/',$ssn)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your SSN is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong SSN."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 [color=rgb(185, 189, 182) !important][size=1em]7 [color=rgb(185, 189, 182) !important][size=1em]8 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$cc = "378282246310005"; [color=rgb(185, 189, 182) !important][size=1em]if [color=rgb(185, 189, 182) !important][size=1em](preg_match('/^(?:4[09]{12}(?:[09]{3})?|5[15][09]{14}|6011[09]{12}|3(?:0[05]|[68][09])[09]{11}|3[47][09]{13})$/', [color=rgb(185, 189, 182) !important][size=1em]$cc)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your credit card number is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong credit card number."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 [color=rgb(185, 189, 182) !important][size=1em]7 [color=rgb(185, 189, 182) !important][size=1em]8 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$url = "[color=rgb(250, 4, 4) !important][size=1em]http://ansoncheung.tk/"; [color=rgb(185, 189, 182) !important][size=1em]if [color=rgb(185, 189, 182) !important][size=1em](preg_match('/^(http|https|ftp):\/\/([AZ09][AZ09_](?:\.[AZ09][AZ09_])+):?(\d+)?\/?/i', [color=rgb(185, 189, 182) !important][size=1em]$url)) { [color=rgb(185, 189, 182) !important][size=1em]echo "Your url is ok."; [color=rgb(185, 189, 182) !important][size=1em]} else { [color=rgb(185, 189, 182) !important][size=1em]echo "Wrong url."; [color=rgb(185, 189, 182) !important][size=1em]} |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]4$url = "[color=rgb(250, 4, 4) !important][size=1em]http://ansoncheung.tk/articles"; [color=rgb(185, 189, 182) !important][size=1em]preg_match('@^(?:[color=rgb(250, 4, 4) !important][size=1em]http://)?([^/]+)@i', $url, $matches); [color=rgb(185, 189, 182) !important][size=1em]$host = $matches[1]; [color=rgb(185, 189, 182) !important][size=1em]echo $host; |
[color=rgb(185, 189, 182) !important][size=1em]1 [color=rgb(185, 189, 182) !important][size=1em]2 [color=rgb(185, 189, 182) !important][size=1em]3 [color=rgb(185, 189, 182) !important][size=1em]4 [color=rgb(185, 189, 182) !important][size=1em]5 [color=rgb(185, 189, 182) !important][size=1em]6 [color=rgb(185, 189, 182) !important][size=1em]7 | [size=1em][color=rgb(185, 189, 182) !important][size=1em]$text = "Sample sentence from AnsonCheung.tk, regular expression has become [color=rgb(185, 189, 182) !important][size=1em]popular in web programming. Now we learn regex. According to wikipedia, Regular [color=rgb(185, 189, 182) !important][size=1em]expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, [color=rgb(185, 189, 182) !important][size=1em]or regexen) are written in a formal language that can be interpreted by a [color=rgb(185, 189, 182) !important][size=1em]regular expression processor"; [color=rgb(185, 189, 182) !important][size=1em]$text = preg_replace("/\b(regex)\b/i", '\1', $text); [color=rgb(185, 189, 182) !important][size=1em]echo $text; |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |