Operating System-phpcsv export is normally opened in the office under the window, but only one column is opened in the MAC System

Source: Internet
Author: User
Csv Export Code: {code ...} in the Apple system, this code only contains one column in excel: in windows, there are four columns in excel: How can I modify this code? To be compatible with multiple systems? [If they are separated by semicolons, the MAC system is normal. In windows, There is only...

Csv export code:

Public function export_csv () {if ($ id = $ this-> get_input ('resultid') = '') {$ this-> msg ('parameter error');} $ result = call_mod_func ('admin/activity_mod ', 'Get _ result', array ($ id )); $ str = "name, email address, mobile phone number ". PHP_EOL; $ str = iconv ('utf-8', 'gb2312', $ str); // Chinese transcoding foreach ($ result ['rows '] as $ row) {$ name = iconv ('utf-8', 'gb2312', $ row ['name']); $ email = $ row ['email ']; $ mobile = $ row ['mobile']; $ weixinid = iconv ('utf-8', 'gb2312 ', $ row ['weixinid']); $ str. = $ name. ','. $ email. ','. $ mobile. ','. $ weixinid. PHP_EOL;} $ filename = date ('ymd', gettime ()). '.csv '; // set the file name header ("Content-type: text/csv"); header ("Content-Disposition: attachment; filename = ". $ filename); header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0'); header ('expires: 0 '); header ('pragma: public '); echo $ str ;}

This Code
In the Apple system, only one column is opened in excel:

In windows, there are four columns opened in excel:

How can I modify this code? To be compatible with multiple systems?
[If they are separated by semicolons, the MAC system is normal and windows has only one column]

Reply content:

Csv export code:

Public function export_csv () {if ($ id = $ this-> get_input ('resultid') = '') {$ this-> msg ('parameter error');} $ result = call_mod_func ('admin/activity_mod ', 'Get _ result', array ($ id )); $ str = "name, email address, mobile phone number ". PHP_EOL; $ str = iconv ('utf-8', 'gb2312', $ str); // Chinese transcoding foreach ($ result ['rows '] as $ row) {$ name = iconv ('utf-8', 'gb2312', $ row ['name']); $ email = $ row ['email ']; $ mobile = $ row ['mobile']; $ weixinid = iconv ('utf-8', 'gb2312 ', $ row ['weixinid']); $ str. = $ name. ','. $ email. ','. $ mobile. ','. $ weixinid. PHP_EOL;} $ filename = date ('ymd', gettime ()). '.csv '; // set the file name header ("Content-type: text/csv"); header ("Content-Disposition: attachment; filename = ". $ filename); header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0'); header ('expires: 0 '); header ('pragma: public '); echo $ str ;}

This Code
In the Apple system, only one column is opened in excel:

In windows, there are four columns opened in excel:

How can I modify this code? To be compatible with multiple systems?
[If they are separated by semicolons, the MAC system is normal and windows has only one column]

This problem is very difficult? No answer ....

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.