PHP Substring Count – String Function

 
    <?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 />";
   }
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.