Hi everyone,
I'm having an issue splitting a string with preg_split.... Here is a sample string:
Where >= could also be <=, ==, !=, < or >
What I need to accomplish is splitting this, and put each of the three parts (item, operator, value) into an array.... Here is how I'm doing this:
This works great so long as the operator is one of ==, !=, <, or >.... but where the operator is >= or <= (as in this case) pcre matches ONLY the > or < so that the resultant array looks like this:
Clearly the operator should be >= and the value should be only 80.... Any ideas of how I could get around this? I did try changing the order (put >= | <= after the < | > in the sub-patter) to no avail... It seems to return only the shortest match.
I could of course write a HACK (if the value starts with = append it to the operator and strip it from the value) but I am so dead set against hacking things together that it hurts me to even consider that as an option.
Thanks!
-Ryan
I'm having an issue splitting a string with preg_split.... Here is a sample string:
Code:
congestion >= 80
What I need to accomplish is splitting this, and put each of the three parts (item, operator, value) into an array.... Here is how I'm doing this:
Code:
$this_expr = preg_split('/(==|>=|<=|<|>|\!=)/U', $rule, -1, PREG_SPLIT_DELIM_CAPTURE);
Code:
$this_expr[0] = congestion; $this_expr[1] = >; $this_expr[2] = =80;
I could of course write a HACK (if the value starts with = append it to the operator and strip it from the value) but I am so dead set against hacking things together that it hurts me to even consider that as an option.
Thanks!
-Ryan
Comment