Validate user inputted PHP code before passing it to eval()

前端 未结 5 1190
傲寒
傲寒 2021-01-12 10:10

Before passing a string to eval() I would like to make sure the syntax is correct and allow:

  1. Two functions: a() and b()
  2. Four operators: /*-+
5条回答
  •  無奈伤痛
    2021-01-12 10:16

    You could use token_get_all(), inspect each token, and abort at the first invalid token.

提交回复
热议问题