substr_count.php : substr_count « String « PHP






substr_count.php

 
<?php
   $buzzwords = array("this", "is", "test");
$talk = <<< talk
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
talk;
   foreach($buzzwords as $bw) {
      echo "The word $bw appears ".substr_count($talk,$bw)." time(s).<br />";
   }
?>
  
  








Related examples in the same category

1.Counting the Occurrences of a Substring
2.Testing for Substrings
3.substr_count() function returns the number of times substring occurs in string.