Dynamic logical expression parsing/evaluation in PHP?

前端 未结 6 481
隐瞒了意图╮
隐瞒了意图╮ 2021-01-11 14:10

I have a need to evaluate user-defined logical expressions of arbitrary complexity on some PHP pages. Assuming that form fields are the primary variables, it would need to:

6条回答
  •  感情败类
    2021-01-11 14:32

    If I understand the problem correctly, you want the users to write out functions in non-PHP, and then have PHP interpret it?

    If so, you could simply take their string and replace "lt" with "<" and "gt" with ">" ... then do eval().

    I have a hunch the problem isn't this simple, but if it is, eval() could do the job. Of course, then you're opening yourself up for any kind of attack.

提交回复
热议问题