简体   繁体   中英

php fputcsv is trims the string value while writing to file

I don't know this question is asked or not. I didn't get his in suggestion.

I'm trying to write some data from database to an csv file. I'm using fputcsv function.

I'm using following code :

$fh = @fopen($fileName, 'w+');
        $writeText['sku'] = $somevalue
        $writeText['attribute_set'] = $somevalue
        $writeText['type'] = $somevalue
        $writeText['default_catalogue_link']= $somevalue
        $writeText['status'] = $somevalue
@fputcsv($fh, $writeText);
        @flush();
@fclose($fh);

Some of the values starts with zero like $writeText['sku'] is 0987 . After writing to the file. I'm getting 987 in the file.

how to prevent this? I need with zero values.

Any help would be usefull. Thanks in advance.

Are you using Excel to open the file? Because Excel interprets it as a number. Try open and see with a text editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM