You can do this with preg_replace_callback
. Use this regex, which looks for a symbol of the form <letter><digits>
between word boundaries:
\b([A-Z])(\d+)\b
and then in the callback the second group's value can be incremented:
$formula = 'IF(B15="","",IF(ISNUMBER(A14),A14+1,IF(ISNUMBER(B3),B3+1,1)))';
echo preg_replace_callback('/\b([A-Z])(\d+)\b/', function ($m) {
return $m[1] . (1 + $m[2]);
}, $formula);
Output:
IF(B16="","",IF(ISNUMBER(A15),A15+1,IF(ISNUMBER(B4),B4+1,1)))
Demo on 3v4l.org
Update
To use an external variable in the callback (as described in the comments), edit the code like this:
$formula = 'IF(B15="","",IF(ISNUMBER(A14),A14+1,IF(ISNUMBER(B3),B3+1,1)))';
$tambah = $adding + ($rekord*$highest);
echo preg_replace_callback('/\b([A-Z])(\d+)\b/', function ($m) use ($tambah) {
return $m[1] . ($tambah + $m[2]);
}, $formula);