There is a certain text (template), in it sometimes there are lines of the form:

[if (health == 1) then (var1) else (var2)] 

How to make so that in PHP the given construction is processed, where: health = is the real variable that is in the script, and the output should be an array, with the results (because there can be several such constructions. The array should contain either var1, or var2 (based on this example, i.e. the array contains the contents of the brackets, depending on the construction.)

  • Will this option suit you: 1. Inside the parentheses, everything that looks like a variable name is preceded by a dollar sign. 2. A return is added to the second and third parentheses. 3. After the second and third parenthesis, a semicolon is put and the resulting string is processed by eval ohm - ReinRaus
  • do you suggest eval ()? I had such an idea, but I thought that it could be implemented in another, more interesting way. - Dmitry Alekseevich
  • @ Dmitry Alekseevich, for example, how? Regular expressions match text to a pattern; they are not capable of computing. - ReinRaus

1 answer 1

Layout and php