I am trying to modify some current code in PHP to extend its functionality. Currently the code allows users of a forum to enter a specific tag and place some numeric parameters between the tags which in turn returns a mathematical solution.
Current working example:
[dice]2d20+3[/dice]
When the user enters this tag in a message the resulting post will contain the following.
Rolling some dice:
2d20(6)(13) +3 = 22
This fine but I am wanting to add the ability to do math with multiple dice (which it currently does not allow for).
Example of desired functionality:
[dice]1d20+3 +(1d4+6) +1d4[/dice]
Example Result:
Rolling some dice:
1d20 (7) + 3 + 1d4 (2) + 6 + 1d4 (3) = 21
(NOTE: Formating the result is not part of this question, just the method)
As you can see in the above, there are two things at play here. First is the functionality to using grouping (parenthesis) and the second is to apply math to the results of multiple die roles.
My problem is two fold. I am not a RegEx programmer and secondly, i am not good enough at PHP to figure out recursion (which I think is required to solve this problem).
In short I am look to modify the current code to allow for any number of nested groupings "()" in addition to allowing for multiple die roles.
Can anyone help?
Start Free Trial