public static function lineIsOpenQuoted($line, $quote, $escape)
    {
        // Returns TRUE if line is valid
        $pos        = 0;
        $quote_open = false;
        $esc_len    = strlen($escape);

        for (; $pos < strlen($line); ++ $pos) {
            $char = $line[$pos];

            // If the character is part of an escape squence, advance the string.
            if (substr($line, $pos, $esc_len) == $escape) {
                $pos += $esc_len - 1; // Subtract one because we advance on loop start.
                continue;
            }

            // Otherwise, toggle the quote flag if this is a quote character
            if ($char == $quote)
                $quote_open = !$quote_open;

            // Continue if the character is anything else.
        }

        if ($quote_open)
            return true;
        else
            return false;
    }