Advertisement

11.01.2007 at 10:00AM PDT, ID: 22932792 | Points: 500
[x]
Attachment Details

Using PHP/RegEx to build algebra ordered operations from string

Asked by cparcell in PHP for Windows, PHP Scripting Language, Regular Expressions

Tags: , ,

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
[+][-]11.01.2007 at 11:28AM PDT, ID: 20195284

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 11:30AM PDT, ID: 20195297

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 12:46PM PDT, ID: 20196031

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 12:51PM PDT, ID: 20196085

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 12:54PM PDT, ID: 20196137

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 12:59PM PDT, ID: 20196173

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 01:01PM PDT, ID: 20196194

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 01:23PM PDT, ID: 20196345

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 01:25PM PDT, ID: 20196360

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 01:26PM PDT, ID: 20196372

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 01:28PM PDT, ID: 20196385

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 01:35PM PDT, ID: 20196435

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.01.2007 at 02:55PM PDT, ID: 20196983

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628