src/Csv.php
protected function _validate_row_condition($row, $condition) {
        $operators = array(
            '=',
            'equals',
            'is',
            '!=',
            'is not',
            '<',
            'is less than',
            '>',
            'is greater than',
            '<=',
            'is less than or equals',
            '>=',
            'is greater than or equals',
            'contains',
            'does not contain',
        );

        $operators_regex = array();

        foreach ($operators as $value) {
            $operators_regex[] = preg_quote($value, '/');
        }

        $operators_regex = implode('|', $operators_regex);

        if (preg_match('/^(.+) (' . $operators_regex . ') (.+)$/i', trim($condition), $capture)) {
            $field = $capture[1];
            $op = $capture[2];
            $value = $capture[3];

            if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/', $value, $capture) && $capture[1] == $capture[3]) {
                $value = strtr($capture[2], array(
                    "\\n" => "\n",
                    "\\r" => "\r",
                    "\\t" => "\t",
                ));

                $value = stripslashes($value);
            }

            if (array_key_exists($field, $row)) {
                if (($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value) {
                    return '1';
                } elseif (($op == '!=' || $op == 'is not') && $row[$field] != $value) {
                    return '1';
                } elseif (($op == '<' || $op == 'is less than') && $row[$field] < $value) {
                    return '1';
                } elseif (($op == '>' || $op == 'is greater than') && $row[$field] > $value) {
                    return '1';
                } elseif (($op == '<=' || $op == 'is less than or equals') && $row[$field] <= $value) {
                    return '1';
                } elseif (($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value) {
                    return '1';
                } elseif ($op == 'contains' && preg_match('/' . preg_quote($value, '/') . '/i', $row[$field])) {
                    return '1';
                } elseif ($op == 'does not contain' && !preg_match('/' . preg_quote($value, '/') . '/i', $row[$field])) {
                    return '1';
                } else {
                    return '0';
                }
            }
        }

        return '1';
    }
protected function _validate_row_condition($row, $condition) {
        $operators = array(
            '=',
            'equals',
            'is',
            '!=',
            'is not',
            '<',
            'is less than',
            '>',
            'is greater than',
            '<=',
            'is less than or equals',
            '>=',
            'is greater than or equals',
            'contains',
            'does not contain',
        );

        $operators_regex = array();

        foreach ($operators as $value) {
            $operators_regex[] = preg_quote($value, '/');
        }

        $operators_regex = implode('|', $operators_regex);

        if (preg_match('/^(.+) (' . $operators_regex . ') (.+)$/i', trim($condition), $capture)) {
            $field = $capture[1];
            $op = $capture[2];
            $value = $capture[3];

            if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/', $value, $capture) && $capture[1] == $capture[3]) {
                $value = strtr($capture[2], array(
                    "\\n" => "\n",
                    "\\r" => "\r",
                    "\\t" => "\t",
                ));

                $value = stripslashes($value);
            }

            if (array_key_exists($field, $row)) {
                if (($op == '=' || $op == 'equals' || $op == 'is') && $row[$field] == $value) {
                    return '1';
                } elseif (($op == '!=' || $op == 'is not') && $row[$field] != $value) {
                    return '1';
                } elseif (($op == '<' || $op == 'is less than') && $row[$field] < $value) {
                    return '1';
                } elseif (($op == '>' || $op == 'is greater than') && $row[$field] > $value) {
                    return '1';
                } elseif (($op == '<=' || $op == 'is less than or equals') && $row[$field] <= $value) {
                    return '1';
                } elseif (($op == '>=' || $op == 'is greater than or equals') && $row[$field] >= $value) {
                    return '1';
                } elseif ($op == 'contains' && preg_match('/' . preg_quote($value, '/') . '/i', $row[$field])) {
                    return '1';
                } elseif ($op == 'does not contain' && !preg_match('/' . preg_quote($value, '/') . '/i', $row[$field])) {
                    return '1';
                } else {
                    return '0';
                }
            }
        }

        return '1';
    }
protected function _validate_row_condition ( $ row , $ condition ) { $ operators = array ( '=' , 'equals' , 'is' , '!=' , 'is not' , '<' , 'is less than' , '>' , 'is greater than' , '<=' , 'is less than or equals' , '>=' , 'is greater than or equals' , 'contains' , 'does not contain' , ) ; $ operators_regex = array ( ) ; foreach ( $ operators as $ value ) { $ operators_regex [ ] = preg_quote ( $ value , '/' ) ; } $ operators_regex = implode ( '|' , $ operators_regex ) ; if ( preg_match ( '/^(.+) (' . $ operators_regex . ') (.+)$/i' , trim ( $ condition ) , $ capture ) ) { $ field = $ capture [ 1 ] ; $ op = $ capture [ 2 ] ; $ value = $ capture [ 3 ] ; if ( preg_match ( '/^([\'\"]{1})(.*)([\'\"]{1})$/' , $ value , $ capture ) && $ capture [ 1 ] == $ capture [ 3 ] ) { $ value = strtr ( $ capture [ 2 ] , array ( "\\n" => "\n" , "\\r" => "\r" , "\\t" => "\t" , ) ) ; $ value = stripslashes ( $ value ) ; } if ( array_key_exists ( $ field , $ row ) ) { if ( ( $ op == '=' || $ op == 'equals' || $ op == 'is' ) && $ row [ $ field ] == $ value ) { return '1' ; } elseif ( ( $ op == '!=' || $ op == 'is not' ) && $ row [ $ field ] != $ value ) { return '1' ; } elseif ( ( $ op == '<' || $ op == 'is less than' ) && $ row [ $ field ] < $ value ) { return '1' ; } elseif ( ( $ op == '>' || $ op == 'is greater than' ) && $ row [ $ field ] > $ value ) { return '1' ; } elseif ( ( $ op == '<=' || $ op == 'is less than or equals' ) && $ row [ $ field ] <= $ value ) { return '1' ; } elseif ( ( $ op == '>=' || $ op == 'is greater than or equals' ) && $ row [ $ field ] >= $ value ) { return '1' ; } elseif ( $ op == 'contains' && preg_match ( '/' . preg_quote ( $ value , '/' ) . '/i' , $ row [ $ field ] ) ) { return '1' ; } elseif ( $ op == 'does not contain' && ! preg_match ( '/' . preg_quote ( $ value , '/' ) . '/i' , $ row [ $ field ] ) ) { return '1' ; } else { return '0' ; } } } return '1' ; }
Validate a row against a single condition

@param array  $row       array with values from a row
@param string $condition specified condition that the row must match

@return string single 0 or 1
Validate a row against a single condition