= 3 which will check if item.foo is greater than or equal to 3; * - ?foo > 3 which will check if item.foo is greater than 3; * - ?foo <= 3 which will check if item.foo is less than or equal to 3; * - ?foo < 3 which will check if item.foo is less than 3; * * - ?foo {} baz which will check if 'baz' is an array element in item.foo * - ?foo {*} baz which will check if 'baz' is an array key in item.foo * - ?foo which will check for a return of a true condition for item.foo; * - ?!foo which will check for a return of a false condition for item.foo; * * The values 0, '', an empty array, and an unset value will all evaluate to false. * * @param string $s * @param array $item * @return bool */ public static function test_condition($s,$item) { if (preg_match('/(.*?)\s\~\=\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if (stripos($x, trim($matches[2])) !== false) { return true; } return false; } if (preg_match('/(.*?)\s\=\=\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x == trim($matches[2])) { return true; } return false; } if (preg_match('/(.*?)\s\!\=\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x != trim($matches[2])) { return true; } return false; } if (preg_match('/(.*?)\s\>\=\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x >= trim($matches[2])) { return true; } return false; } if (preg_match('/(.*?)\s\<\=\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x <= trim($matches[2])) { return true; } return false; } if (preg_match('/(.*?)\s\>\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x > trim($matches[2])) { return true; } return false; } if (preg_match('/(.*?)\s\>\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x < trim($matches[2])) { return true; } return false; } if (preg_match('/[\$](.*?)\s\{\}\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if (is_array($x) && in_array(trim($matches[2]), $x)) { return true; } return false; } if (preg_match('/(.*?)\s\{\*\}\s(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if (is_array($x) && array_key_exists(trim($matches[2]), $x)) { return true; } return false; } // Ordering of this check (for falsiness) with relation to the following one (check for truthiness) is important. if (preg_match('/\!(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if (!$x) { return true; } return false; } if (preg_match('/(.*?)$/', $s, $matches)) { $x = ((array_key_exists(trim($matches[1]),$item)) ? $item[trim($matches[1])] : EMPTY_STR); if ($x) { return true; } return false; } return false; } }