[ create a new paste ] login | about

Link: http://codepad.org/LSpTq0g4    [ raw code | output | fork ]

PHP, pasted on Nov 28:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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);


Output:
1
2


Create a new paste based on this one


Comments: