Home > Backend Development > PHP Tutorial > php生成的csv, 没法完整显示带前导0的数字

php生成的csv, 没法完整显示带前导0的数字

WBOY
Release: 2016-06-13 12:29:19
Original
1183 people have browsed it

php生成的csv, 无法完整显示带前导0的数字

php生成csv文件时,如果数字的第一位为0的话,显示时则不会显示第一个0

可以在php中做特殊处理,使得生成的csv在显示时能显示出第一个0

有两种方法可以实现:

1、给数字加上引号,并且在引号前面再加上个等号,如数字0555,,则生成时为="0555"

2、在数字前面加上制表符,如是数字0555,则生成时为\t0555

<code>$arr    = array (    array ('111', 2222, '0555'),    array ('222', 3333, '0666'));$fp    = fopen('t.csv', 'w');foreach ($arr as $row) {    fputcsv($fp, array_map('h', $row));}fclose($fp);function h($v) {    if (($v{0} == '0') && is_numeric($v)) {        $v    = '="' . $v . '"';    //第一种方式        //$v   = "\t{$v}";    //第二种方式    }    return $v;}</code>
Copy after login

转载自:http://www.9958.pw/post/php_cvs

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template