Csv generated by php, cannot display the complete number with leading 0-php Tutorial

Source: Internet
Author: User
The csv file generated by php cannot fully display the numbers with leading 0. when a csv file is generated by php, if the first digit of the number is 0, the first 0 is not displayed.

You can perform special processing in php so that the generated csv can display the first 0

There are two ways to achieve this:

1. enclose the number with quotation marks and add an equal sign before the quotation marks. for example, if the number is 0555, the value is = "0555"

2. add a tab to the front of the number. if the number is 0555, \ t0555 is generated.

$ Arr = array ('20160301', 111, '20160301'), array ('20160301', 2222, '20160301'); $ 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. '"'; // method 1 // $ v =" \ t {$ v} "; // method 2} return $ v ;}

Reprinted from: http://www.9958.pw/post/php_cvs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.