Right, what I have is page content (in $index_content) which in places contains code for referencing variables, arrays etc, for example:
Code: Select all
There are <=member_count> members
and I have a preg_replace replace the tag with the value of $member_count at the time the preg_replace is executed.
The current code for variables and arrays is:
Code: Select all
$index_content = preg_replace("/<=([_a-z0-9]+)>/ie", "$$1", $index_content);
$index_content = preg_replace("/<=([_a-z0-9]+)\[([_a-z0-9]+)\]>/ie", "$$1[$2]", $index_content);
The first one for replacing calls to variables, and the second one for one-dimensional arrays in format <=array[key]>.
Now, I could just add another line for two-dimensional arrays (since I'd almost never go further than two), but I'd like to have a single line of code which handles all of the variables, and arrays with as many dimensions as I like.
What I tried was this:
Code: Select all
$index_content = preg_replace("/<=([_a-z0-9]+)(\[[_a-z0-9]\]+)>/ie", "$$1$2", $index_content);
basically moving the square brackets to find the array keys into the parentheses for the second callback. The idea is that $2 in the replace would be something like "[key1][key2]".
After doing a bit more testing, the T_IS_SMALLER_OR_EQUAL error is just a later problem caused by the fact that the preg_replace isn't matching the code; it isn't related. The real problem is that the regexp just isn't correct.
That said, if it wouldn't be possible to do it easily, or less effective, I could just add that extra preg_replace for two-dim arrays, so it's not imperative that I get this sorted out.