public static function smartSplit($data, $delimiter = ';', $quote = "'", $escape = "\\'", $limit = null)
    {
        $results = array ();

        // Split like normal to start.
        $lines = explode($delimiter, $data);

        if (empty ($lines))
            return array ();

        $broke = false;
        for ($i = 0; $i < count($lines); $i++) {
            $line = $lines[$i];

            // Now, add each fully quoted line
            if (!self::lineIsOpenQuoted($line, $quote, $escape))
                $results[] = $line;
            else {
                // Otherwise, add each new line until we find the first closed line
                do {
                    $line .= $delimiter . $lines[++ $i];
                } while (($i +1) < count($lines) && self::lineIsOpenQuoted($line, $quote, $escape));

                $results[] = $line;
            }
        }


        if (!is_null($limit) && count($results) > $limit) {
            $newresults = array();
            for ($i = 0; $i < ($limit-1); $i++) {
                $newresults[] = array_shift($results);
            }
            $newresults[] = implode($delimiter, $results);
            return $newresults;
        }

        return $results;
    }