< p > text < p >
$str = '< p > text </p>';
$count = 0;
$str = preg_replace_callback('/< ?\/?\w+ ?\>/', function() use(&$count) {
$count++;
return "#p$count";
}, $str);
$str = '< p > text </p> <b> fdsgdfsg</b> <p>???</p> <div>hello, world!!< /div>';
$count = [];
$str = preg_replace_callback('/< ?\/?(\w+) ?\>/', function($matches) use(&$count) {
$key = $matches[1];
$count[$key] = isset($count[$key]) ? $count[$key] + 1 : 1;
return "#$key$count[$key]";
}, $str);