/* string search is the main application of regular expressions. In PHP, the main function that can be used to match regular expressions in the Perl style is preg_match (). The function prototype is as follows
int preg_match (string pattern, string subject [, array matches [, int flags])
Search for Pattern in subject. $ Matches [0] will contain the text that matches the entire pattern.
$ matches [1] will contain the text that matches the child pattern in the first captured parentheses. So on
*/
$ text = "PHP is the Web scripting language of choice. ";
Print (" Search/"PHP/"/n "in text/" {$ text ");
If (preg_match ("/PHP/I", $ text )) {// the "I" after the pattern delimiter indicates that the big water writes are not distinguished during search
Print "-> find a match/n ";
}else {
Print "-> mode not found/n";
}
$ Text = "PHP is the website scripting language of choice .";
Print ("search for words/" Web/"/n" in text/"{$ text ");
If (preg_match ("// bweb/B/I", $ text) {// "/B" after the pattern delimiter indicates the word boundary, therefore, only the independent word "Web" can match
Print "-> find a match/n ";
} Else {
Print "-> mode not found/n ";
}
Print ("search for words/" Web/"/n" in text/"{$ text ");
If (preg_match ("/web/I", $ text )){
Print "-> find a match/n ";
} Else {
Print "-> mode not found/n ";
}
$ Text = "http://www.php.net/index.html ";
Print ("Get host name and domain name/n from ur/" {$ text ");
If (preg_match ("/^ (http :////)? ([^ //] +)/I ", $ text, $ matches) {// a subexpression enclosed in parentheses
$ Host = $ matches [2];
Print "-> Host Name: $ host/n ";
Preg_match ("/[^ /. //] + /. [^ /. //] + $/", $ host, $ matches); // obtain the following two segments from the host name
Print "-> Domain Name: {$ matches [0]}/N ";
}
?>