Try something like this:
function pregRepler($matches) {
static $matchcount = 0;
// do stuff
$matchcount++;
}
This works better with an anonymous function, as I mentioned in my answer to your other question, as this will avoid problems if you have multiple calls to preg_replace_callback
.