Substring count : Sub string « String « PHP






Substring count


<?php
   $buzzwords = array("ex", "te", "xt");
$talk = <<< talk
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text  
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
talk;
   foreach($buzzwords as $bw) {
      echo "The word $bw appears ".substr_count($talk,$bw)." time(s).<br />";
   }
?>

           
       








Related examples in the same category

1.Substring replace
2.substr($String, -3)
3.substr($String, 3, 5)
4.substr($String, -3, 5) (2)
5.substr($String, -3, -5) (3)
6.substr($String, 3, -5) (4)
7.substr($string, 3)
8.Extracting Part of a String with substr()