php preg_mach code example

Example 1: preg_match in php

<?php
//Syntex : int preg_match( $pattern, $input, $matches, $flags, $offset)
  
// Declare a variable and initialize it 
$str = "Check For Testing."; 
  
// case-Insensitive search for the word "Check" 
if (preg_match("/\bCheck\b/i", $str, $match))  
    echo "Matched!"; 
else
    echo "not matched";   
  

// Output : Matched
?>

Example 2: preg_match in php

<?php
$my_url = "www.guru99.com";
if (preg_match("/guru/", $my_url))
{
	echo "the url $my_url contains guru";
}
else
{
	echo "the url $my_url does not contain guru";
}
?>

Tags:

Php Example