I want a user to enter a string into a form (or use a js interface to build the string for them) which can then be logically evaluated server side.
For example: The event admin writes into a text area "((36&&37)||(37&&38))&&~42" which goes into a fee_option table. A registrant picked options 37 and 38. The registrant is then charge a certain fee because the expression evaluates true. I can see a basic option of replacing each number with the result of in_array($one_number,$options_selected_by_user) and then running that through some kind of regex security and then sticking that into an eval($str), but this is really just a dumb example.
My questions are then:
- Is there a conventional syntax for writing expressions to be evaluated apart from writing code to stick into an eval statement?
- Is there a PHP library, script, or even blog post that provides help when writing such a thing? Put another way - does everyone write user entered conditional statements for form builders and such from scratch everytime?
- Is there a javascript library specifically designed to build logical statements via a user interface, ie. grouping ors, ands, and nots, with a little math too probably.