尝试编写一个函数来处理传递的 ID 公式

问题描述 投票:0回答:0

我想要一个 PHP 函数来接受这个例子的意思:

parse_id_formula($formula, $id_column = 'id'); // =>

  • “1”=
    id=1
    .
  • “1|2|3|4|20|29|55”=
    id in (1, 2, 3, 4, 20, 29, 55)
    .
  • “1>19”=
    id between 1 and 19
    .
  • "1>19!10" =
    id between 1 and 19 and id not in (10)
    .
  • "1>19!10|11|12" =
    id between 1 and 19 and id not in (10, 11, 12)
    .
  • "1>19!10>15" =
    id between 1 and 19 and id not between 10 and 15
    .
  • ">1" =
    id > 1
    .
  • ">=1" =
    id >= 1
    .
  • ">1<10" =
    id > 1 and id < 10
    .
  • ">=1<=10" =>
    id >= 1 and id <= 10
    .
  • "<1" =
    id < 1
    .
  • "<=1" =
    id <= 1
    .
  • ">1<10!5" =
    id > 1 and id < 10 and id != 5
    .
  • ">=1<=10!5" =
    id >= 1 and id <= 10 and id != 5
    .

以上是唯一有效的接受公式,以下是无效的(只是为了知道写的情况而不是随机公式,不要将错误消息返回给用户):

  • "|1" = 无效,因为不是以整数开头。
  • “1|” = 无效,因为以键而不是数字结尾。
  • “1|1|2|3”= 无效,因为检测到重复的 ID。
  • “1||2”= 无效,因为
    |
    键重复。
  • "1>>20" = 无效,因为
    >
    键重复。
  • "1>20!!15" = 无效,因为
    !
    键重复。
  • "1>19!33" = 无效,因为排除值 33 超出范围。
  • ">1<10!25" = invalid because excluded value 25 is out of the range.
  • "1>19!25>35" = 无效,因为排除值 25 不在基数范围内。
  • "1>19!10>35" = 无效,因为排除值 25 不在(也不在)基准范围内。
  • "<0" or "<=0" = invalid because not logical id.

我试着写这个函数,但堆满了正则表达式。感谢您的帮助。

php regex
© www.soinside.com 2019 - 2024. All rights reserved.