简体   繁体   English

php fputcsv是写入文件时修剪字符串值

[英]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. 我正在尝试将一些数据从数据库写入csv文件。 I'm using fputcsv function. 我正在使用fputcsv函数。

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 . 一些值以零开头,例如$writeText['sku']0987 After writing to the file. 写入文件后。 I'm getting 987 in the file. 我的文件中是987

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? 您是否正在使用Excel打开文件? Because Excel interprets it as a number. 因为Excel会将其解释为数字。 Try open and see with a text editor. 尝试打开并使用文本编辑器查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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