PHP program to demonstrate the regular expression to count the occurrence of given substring

bookmark

<?php
//PHP program to demonstrate the regular expression 
//to count the occurrence of given substring.

$str = "India is a country located in asia";
$pattern = "/in/i";

$count = preg_match_all($pattern, $str);

printf("Total occurrences of are: %d", $count);
?>


Output
Total occurrences of are: 2