How could I use string commands to process a PHP variable that contains strings that are formatted with if/then logic (as shown below), so that after the variable has been processed it will only include the text that is contained in the conditions that are true, and all of the logic language (i.e. everything between [ ]) and all of the text that follows false conditions are dropped from that variable.
Example of the text inside of the PHP variable that will be processed:
[IF $variable1=”Y”] Use this text[
IF $variable2=”Y"] Use the additional text[
ENDIF]
[ELSE] Use this alternate text only[
[ENDIF]
In other words, I’d like the PHP to read the variable, locate the first “[IF” string then check the condition that is in the remaining part of the string before the next “]” based on the current value of the $variable in PHP that was passed to that PHP page. If that condition for $variable1 is true, then PHP would delete the [IF $variable1="y"] and leave the “Use this text” alone, and proceed to evaluate the next IF statement. If that next condition for $variable2 is true, then it would leave “use the additional text” otherwise that would be dropped along with the [ENDIF].
Then, somewhere along the way, if the outside [IF] was true, then the corresponding [ELSE] branch would be dropped and so would the closing [ENDIF]. What I would be left with would be a PHP variable that could be printed that contained only the “true” text.
This would of course need to loop through the variable until all conditions had been evaluated. Note, too that formatting between the [ ] should not matter, whether there are spaces, tabs, or new lines between the words as long as there is something between the IF and the condition to be evaluated. Thanks in advance.