Example #1
0
function compare($value1, $value2, $operator)
{
    if ($operator == "=") {
        return $value1 == $value2;
    }
    if ($operator == ">") {
        return $value1 > $value2;
    }
    if ($operator == "<") {
        return $value1 < $value2;
    }
    if ($operator == "<>" || $operator == "!=") {
        return $value1 != $value2;
    }
    if ($operator == ">=") {
        return $value1 >= $value2;
    }
    if ($operator == "<=") {
        return $value1 <= $value2;
    }
    if ($operator == "LIKE") {
        return compare_like($value1, $value2);
    }
    if ($operator == "NOT LIKE") {
        return !compare_like($value1, $value2);
    }
    if ($operator == "IN") {
        $list = preg_split("/[(,) ]+/", $value2, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($list as $listVal) {
            if (!is_numeric($listVal)) {
                if (has_quotes($listVal)) {
                    remove_quotes($listVal);
                }
                if ("{$listVal}" == "{$value1}") {
                    return 1;
                }
            } else {
                if ($listVal == $value1) {
                    return 1;
                }
            }
        }
        return 0;
    }
    if ($operator == "NOT IN") {
        $list = preg_split("/[(,) ]+/", $value2, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($list as $listVal) {
            if (!is_numeric($listVal)) {
                if (has_quotes($listVal)) {
                    remove_quotes($listVal);
                }
                if ("{$listVal}" == "{$value1}") {
                    return 0;
                }
            } else {
                if ($listVal == $value1) {
                    return 0;
                }
            }
        }
        return 1;
    }
    return false;
}
Example #2
0
function compare($value1, $value2, $operator)
{
    if ($operator == "=") {
        return $value1 == $value2;
    }
    if ($operator == ">") {
        return $value1 > $value2;
    }
    if ($operator == "<") {
        return $value1 < $value2;
    }
    if ($operator == "<>" || $operator == "!=") {
        return $value1 != $value2;
    }
    if ($operator == ">=") {
        return $value1 >= $value2;
    }
    if ($operator == "<=") {
        return $value1 <= $value2;
    }
    if (trim(strtoupper($operator)) == "LIKE") {
        return compare_like($value1, $value2);
    }
    if (trim(strtoupper($operator)) == "NOT LIKE") {
        return !compare_like($value1, $value2);
    }
    return false;
}