<?php
function substr_count_overlap($string, $needle) {
$count = 0;
$start = 0;
while(1) {
$found = strpos($string, $needle, $start);
if($found !== FALSE) {
$count++;
$start = $found + 1;
} else return $count;
}
return $count;
}
$myString = 'bababa';
$search = 'baba';
echo substr_count_overlap($myString, $search);