Php and mail are sent with csv attachments. after the file is downloaded and opened, garbled text is displayed.

Source: Internet
Author: User
SegmentFault (www. sf. gg) is a leading developer technology community in China. We hope to provide programmers with a pure and high-quality technology exchange platform to learn, communicate and grow with developers and create an era for developers!

Reply content:

The two encoding formats are inconsistent.

// CSV Excel supports GBK encoding and must be converted; otherwise, garbled code $ content = iconv ('utf-8', 'gbk // ignore ', $ content );

Two-dimensional array:

Foreach ($ dataArr as $ key => $ value) {foreach ($ value as $ k1 => $ v1) {$ value [$ k1] = iconv ('utf-8', 'gbk // ignore ', $ v1);} fputcsv ($ fh, $ value );} fclose ($ fh );

It should be about encoding.

// Transcode the header: $ header_data = ['first Column', 'second column']; echo iconv ('utf-8', 'gbk // transtranstranscoder ', '"'. implode ('","', $ header_data ). '"'. "\ n ");

Try it ~

For details, refer to: PHP to read/export CSV files.

Check whether the file content encoding is normal for the csv file you generated or the csv file you sent before?

Mail says it's strange to me

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.