Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to force enclosing certain (or all) fields? #34

Open
Manc opened this issue Mar 25, 2014 · 3 comments
Open

Is there a way to force enclosing certain (or all) fields? #34

Manc opened this issue Mar 25, 2014 · 3 comments

Comments

@Manc
Copy link

Manc commented Mar 25, 2014

As far as I know, by CSV standard you may enclose fields even if there is no real or obvious need.

In my case I'm dealing with a field for a German 5-digits postal code that may start with a zero (e.g. "01234"), but must always be interpreted as a string. Importing the CSV file with software such as Excel, the value is interpreted as number (1234) if it's not enclosed.

I tried a CallbackCollection and cast all values to string, but that didn't make any difference.

I could add a whitespace to numeric values, but then the CSV data contains whitespaces, which isn't great either.

Is there an option to force enclosing a field? Or at least a better trick than adding a whitespace?

@Manc
Copy link
Author

Manc commented Mar 25, 2014

Because I needed a quick and dirty solution I had to implement the CSV export myself. So I'm alright for now. If goodby/csv doesn't support force-enclosing values, I hereby suggest this as a new feature for a future version. Thanks!

@jjeaton
Copy link

jjeaton commented Dec 22, 2014

👍 for this

@FadelChafai
Copy link

Hi,

u can use this approach to deal with your problem

/** $line is an array, each value is encapsulated by double quotes **/

private function addLine($line)
{
    $csv = implode(";", $line) . PHP_EOL;

    file_put_contents($this->_file, $csv, FILE_APPEND);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants