PHP and email are sent with csv attachments. After downloading and opening, the content text is garbled. Please solve it.

WBOY
Release: 2016-09-19 09:16:25
Original
1178 people have browsed it

PHP and email are sent with csv attachments. After downloading and opening, the content text is garbled. Please solve it.

PHP and email are sent with csv attachments. After downloading and opening, the content text is garbled. Please solve it.

Reply content:

PHP and email are sent with csv attachments. After downloading and opening, the content text is garbled. Please solve it.

PHP and email are sent with csv attachments. After downloading and opening, the content text is garbled. Please solve it.

Result from inconsistent encoding formats on both sides.

<code>//CSV的Excel支持GBK编码,一定要转换,否则乱码
$content = iconv('utf-8', 'gbk//ignore', $content);
</code>
Copy after login

Two-dimensional array:

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

It should be an encoding problem.

<code>//对表头进行转码:
$header_data = ['第一列','第二列'];
echo iconv('utf-8','gbk//TRANSLIT','"'.implode('","',$header_data).'"'."\n");
</code>
Copy after login

Try it~

For specific methods, please refer to: PHP reading/exporting CSV files

First confirm, is the encoding of the content of the csv file you generated or the csv file you sent before normal?

The email said it was my fault

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!