I have the folowing code:
<?php
$subject = "Replace ? question mark in brackets [? with ? incremental ??]? digits";
echo incremental_replace($subject);
// i want the folowing:
// Replace ? question mark in brackets [1 with 2 incremental 34]? digits
I want all the ? in the brackets to be replaced. Also, the number and position of ? can change.
How do i do that with php ? I think this can be done with preg_replace, but i don’t know how.
if brackets are not nested, then the following would be enough
otherwise use a parser:
A regular expression for nested brackets is possible but will be too long and messed up.
Note by OP: If the replacements are not incremental digits but an array, you can do the folowing: