- var_dump: documentation ( source)
- preg_replace_callback: documentation ( source)
<?php
$string_source = 'blabla[Sun][Sun]blabla[Moon][Moon][Moon]blabla[Sun][Sun][Sun][Sun]blabla[Venus]';
$string_source = preg_replace_callback('/(\[[^[\]]+\])+/', function($matches)
{
return $matches[1].'['.(strlen($matches[0])/strlen($matches[1])).']';
}, $string_source);
var_dump($string_source);