<?php
$output = '[vc_tab [vc_tab [vc_tab [vc_tab [vc_tab';
$active = 3; // target occurrence
$occurrence = 0; // counter
'/\[vc_tab/',
function ($matches) use(&$occurrence, $active) {
return ++$occurrence != $active
? $matches[0]
: '[vc_tab active="true"';
},
$output
);
echo $output;
PD9waHAKCiRvdXRwdXQgPSAnW3ZjX3RhYiBbdmNfdGFiIFt2Y190YWIgW3ZjX3RhYiBbdmNfdGFiJzsKCiRhY3RpdmUgPSAzOyAgICAgLy8gdGFyZ2V0IG9jY3VycmVuY2UKJG9jY3VycmVuY2UgPSAwOyAvLyBjb3VudGVyCiRvdXRwdXQgPSBwcmVnX3JlcGxhY2VfY2FsbGJhY2soCiAgICAnL1xbdmNfdGFiLycsCiAgICBmdW5jdGlvbiAoJG1hdGNoZXMpIHVzZSgmJG9jY3VycmVuY2UsICRhY3RpdmUpIHsKICAgICAgICByZXR1cm4gKyskb2NjdXJyZW5jZSAhPSAkYWN0aXZlCiAgICAgICAgICAgID8gJG1hdGNoZXNbMF0KICAgICAgICAgICAgOiAnW3ZjX3RhYiBhY3RpdmU9InRydWUiJzsKICAgIH0sCiAgICAkb3V0cHV0Cik7CgplY2hvICRvdXRwdXQ7