how can I count number of occurance of a word in a string while ignoring cases

Posted by Ronny on Stack Overflow See other posts from Stack Overflow or by Ronny
Published on 2012-09-23T21:12:02Z Indexed on 2012/09/23 21:37 UTC
Read the original article Hit count: 209

Filed under:

I am trying to count the number of occurance of a given word while ignoring cases. I have tried

<?php 
 $string = 'Hello World! EARTh in earth and EARth';//string to look into.
  if(stristr($string, 'eartH')) {
    echo 'Found';// this just show eartH was found.
  }
  $timesfound = substr_count($string, stristr($string, 'eartH'));// this count how many times. 

  echo $timesfound; // this outputs 1 instead of 3.

© Stack Overflow or respective owner

Related posts about php