public function separator($firstLines, $delimiter='"')
    {
        $lines = $this->toCheckableLines($firstLines);

        $separatorsByCount = $this->sortSeparatorsByHighestCount($lines[0], $delimiter);
        $highestCount = max(array_keys($separatorsByCount));

        // If the highest count of colums is smaller than 2 there should be
        // no separator at all. If the next lines are seem to have more than one
        // detection should fail.
        if ($highestCount < 2) {
            return '';
        }

        foreach ($separatorsByCount as $count=>$separators) {
            if ($count < 2) {
                continue;
            }
            foreach ($separators as $separator) {
                if (!$this->eachLineHasColumnCountOf($lines, $count, $separator, $delimiter)) {
                    continue;
                }
                return $separator;
            }
        }

        // if we didnt find an applicable separator until here we have to fail
        throw new DetectionFailedException("The csv file seems to have $highestCount columns but the following lines contains another count of columns");
    }
public function separator($firstLines, $delimiter='"')
    {
        $lines = $this->toCheckableLines($firstLines);

        $separatorsByCount = $this->sortSeparatorsByHighestCount($lines[0], $delimiter);
        $highestCount = max(array_keys($separatorsByCount));

        // If the highest count of colums is smaller than 2 there should be
        // no separator at all. If the next lines are seem to have more than one
        // detection should fail.
        if ($highestCount < 2) {
            return '';
        }

        foreach ($separatorsByCount as $count=>$separators) {
            if ($count < 2) {
                continue;
            }
            foreach ($separators as $separator) {
                if (!$this->eachLineHasColumnCountOf($lines, $count, $separator, $delimiter)) {
                    continue;
                }
                return $separator;
            }
        }

        // if we didnt find an applicable separator until here we have to fail
        throw new DetectionFailedException("The csv file seems to have $highestCount columns but the following lines contains another count of columns");
    }
public function separator ( $ firstLines , $ delimiter = '"' ) { $ lines = $ this -> toCheckableLines ( $ firstLines ) ; $ separatorsByCount = $ this -> sortSeparatorsByHighestCount ( $ lines [ 0 ] , $ delimiter ) ; $ highestCount = max ( array_keys ( $ separatorsByCount ) ) ; // If the highest count of colums is smaller than 2 there should be // no separator at all. If the next lines are seem to have more than one // detection should fail. if ( $ highestCount < 2 ) { return '' ; } foreach ( $ separatorsByCount as $ count => $ separators ) { if ( $ count < 2 ) { continue ; } foreach ( $ separators as $ separator ) { if ( ! $ this -> eachLineHasColumnCountOf ( $ lines , $ count , $ separator , $ delimiter ) ) { continue ; } return $ separator ; } } // if we didnt find an applicable separator until here we have to fail throw new DetectionFailedException ( "The csv file seems to have $highestCount columns but the following lines contains another count of columns" ) ; }
Detect the separator char. CSV Files with one line are invalid by
definition.

@param string $firstLines
@param string $delimiter (optional)

@return string
Detect the separator char . CSV Files with one line are invalid by definition .