<?PHP $str = "<li><a href=\"http://www.endmemo.com/index.php\">EndMemo</a></li>" echo substr_count($str, "li"); //result is 2 ?>
If you want to count a pattern of substrings and need to use regular expression,
the
<?PHP $str = "<li><a href=\"http://www.endmemo.com/index.php\">EndMemo</a></li>" $cnt = preg_match_all("/\<[^\>]+\>/",$str, $mats); echo $cnt; //result is 4 ?>