thephpleague / csv

CSV data manipulation made easy in PHP
https://csv.thephpleague.com
MIT License
3.34k stars 336 forks source link

multi-character delimiter not supported #400

Closed aand18 closed 4 years ago

aand18 commented 4 years ago
Q A
Version 9.6.1

Question

Hello!

I have to generate a file that uses three characters as delimiter (don't ask why -_- ).

Any reason thephpleague/csv doesn't support multi-character delimiters?

An exception is thrown at

League\Csv\AbstractCsv::setDelimiter() expects delimiter to be a single character ;@/ given

  at C:\www\illico_feed_generator\vendor\league\csv\src\AbstractCsv.php:397
    393▕
    394▕             return $this;
    395▕         }
    396▕
  ➜ 397▕         throw new InvalidArgument(sprintf('%s() expects delimiter to be a single character %s given', __METHOD__, $delimiter));
    398▕     }
    399▕
    400▕     /**
    401▕      * Sets the field enclosure.

Thanks! A.

nyamsprod commented 4 years ago

@aand18 thanks for using the library. As explained by the exception only single character are supported as delimiter. Nevertheless, you may use the stream filter capabilities of the package if you want to use multi-bytes delimiter characters. For how to do it please refer to stack overflow or any other PHP help forum as this is an expected behaviour.

aand18 commented 3 years ago

@nyamsprod thank you for pointing me to some solutions!

Sorry if may fail to see the bigger picture, I'm not intimately familiar with the source code. Looks like it shouldn't make a difference, just splitting a string by three chars instead of one. I was wondering if there was maybe a historic reason to force single byte? Thanks

nyamsprod commented 3 years ago

@aand18 parsing and generating CSV is done using underlying PHP mechanism and it is not done using splitting characters please refer to PHP documentation about CSV functions to see how it is done.