/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php //Some regex functions: //A better solution for validate email syntax is using filter_var. echo "Your email is ok."; } else { echo "Wrong email address format."; } //Validate username, consist of alpha-numeric (a-z, A-Z, 0-9), underscores, and has minimum 5 character and maximum 20 character. //You could change the minimum character and maximum character to any number you like. $username = "user_name12"; echo "Your username is ok."; } else { echo "Wrong username format."; } //Validate domain $url = "http://komunitasweb.com/"; if (preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $url)) { echo "Your url is ok."; } else { echo "Wrong url."; } //Extract domain name from certain URL $url = "http://komunitasweb.com/index.html"; $host = $matches[1]; echo $host; //Highlight a word in the content $text = "Sample sentence from KomunitasWeb, regex has become popular in web programming. Now we learn regex. According to wikipedia, Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor"; echo $text; ?>