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;
    }
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;
    }
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 ; }
Split a string around a delimiter, taking into account quoted substrings

@param string $data      big string with data
@param string $delimiter Field delimiter
@param string $quote     quote field character
@param string $escape    escaped quote character
@param int    $limit     Return at most this many parts

@return array of all splitted lines
Split a string around a delimiter taking into account quoted substrings