Hi all,
I would like to parse a string containing key operator and value combinations like this:
type=location&postdate>10-12-2013&published!=0
The first step is to explode it based on & of course. But I am looking for an effective way to parse the rest. I could use a if, ifelse, ifelse to search for the operator and then explode on that, like this:
if (strpos('<=', $var) > 0)
{
$arr = explode('<=', $var);
$operator = '<=';
$key = $arr[0];
$value = $arr[1];
}
ifelse (strpos('>=', $var) > 0)
{
$arr = explode('>=', $var);
$operator = '>=';
$key = $arr[0];
$value = $arr[1];
}
etc...
But that is very ugly. Do any of you have any suggestions? Maybe regex?
Thanks in advance,