function parse($string){
$counter = 0;
$string = preg_replace("_\\[b\\](.*?)\\[/b\\]_si", \'\'. $counter .\'. $1&l
I would solve it with a small class with the counter as property and the callback is a method of the class.
class Increaser {
private $counter;
public function replace($string) {
$this->counter = 0;
return preg_replace_callback("_\[b\](.*?)\[/b\]_si", array($this, 'createReplacement'), $string);
}
private function createReplacement($matches) {
++$this->counter;
return ''. $this->counter .'. ' . $matches[1] . '';
}
}