28 January 2012

count the occurence of a word in a string

<?php
$str="hi how how r you how?";
echo substr_count($str, 'how');
?>

this will give outpus as "3"
since "how" occured in the string 3 times. 

No comments:

Post a Comment