1<?php
2//Syntex : int preg_match( $pattern, $input, $matches, $flags, $offset)
3
4// Declare a variable and initialize it
5$str = "Check For Testing.";
6
7// case-Insensitive search for the word "Check"
8if (preg_match("/\bCheck\b/i", $str, $match))
9 echo "Matched!";
10else
11 echo "not matched";
12
13
14// Output : Matched
15?>
1<?php
2 $line = "Vi is the greatest word processor ever created!";
3 // perform a case-Insensitive search for the word "Vi"
4
5 if (preg_match("/\bVi\b/i", $line, $match)) :
6 print "Match found!";
7 endif;
8?>
1if (preg_match("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
2 echo "A match was found.";
3} else {
4 echo "A match was not found.";
5}
1if(!preg_match('/^\[a-zA-Z]+$/',$input)) {
2 // String contains not allowed characters ...
3}
1<?php
2$my_email = "name@company.com";
3if (preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/", $my_email)) {
4echo "$my_email is a valid email address";
5}
6else
7{
8 echo "$my_email is NOT a valid email address";
9}
10?>
1preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) : int