1. <small id='yAPDN'></small><noframes id='yAPDN'>

          <bdo id='yAPDN'></bdo><ul id='yAPDN'></ul>
      2. <legend id='yAPDN'><style id='yAPDN'><dir id='yAPDN'><q id='yAPDN'></q></dir></style></legend>
      3. <i id='yAPDN'><tr id='yAPDN'><dt id='yAPDN'><q id='yAPDN'><span id='yAPDN'><b id='yAPDN'><form id='yAPDN'><ins id='yAPDN'></ins><ul id='yAPDN'></ul><sub id='yAPDN'></sub></form><legend id='yAPDN'></legend><bdo id='yAPDN'><pre id='yAPDN'><center id='yAPDN'></center></pre></bdo></b><th id='yAPDN'></th></span></q></dt></tr></i><div id='yAPDN'><tfoot id='yAPDN'></tfoot><dl id='yAPDN'><fieldset id='yAPDN'></fieldset></dl></div>
        <tfoot id='yAPDN'></tfoot>

        在 PHP 中为用户创建一个 CSV 文件

        时间:2024-08-22
      4. <tfoot id='K7Jpa'></tfoot>
            <bdo id='K7Jpa'></bdo><ul id='K7Jpa'></ul>
              <tbody id='K7Jpa'></tbody>

              <legend id='K7Jpa'><style id='K7Jpa'><dir id='K7Jpa'><q id='K7Jpa'></q></dir></style></legend>
                1. <small id='K7Jpa'></small><noframes id='K7Jpa'>

                  <i id='K7Jpa'><tr id='K7Jpa'><dt id='K7Jpa'><q id='K7Jpa'><span id='K7Jpa'><b id='K7Jpa'><form id='K7Jpa'><ins id='K7Jpa'></ins><ul id='K7Jpa'></ul><sub id='K7Jpa'></sub></form><legend id='K7Jpa'></legend><bdo id='K7Jpa'><pre id='K7Jpa'><center id='K7Jpa'></center></pre></bdo></b><th id='K7Jpa'></th></span></q></dt></tr></i><div id='K7Jpa'><tfoot id='K7Jpa'></tfoot><dl id='K7Jpa'><fieldset id='K7Jpa'></fieldset></dl></div>

                  本文介绍了在 PHP 中为用户创建一个 CSV 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 MySQL 数据库中有数据.我正在向用户发送一个 URL,以便将他们的数据作为 CSV 文件导出.

                  I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.

                  我已经涵盖了链接、MySQL 查询等的电子邮件.

                  I have the e-mailing of the link, MySQL query, etc. covered.

                  当他们点击链接时,我怎样才能弹出一个窗口来下载带有 MySQL 记录的 CVS?

                  How can I, when they click the link, have a pop-up to download a CVS with the record from MySQL?

                  我已经掌握了获取记录的所有信息.我只是不明白如何让 PHP 创建 CSV 文件并让他们下载扩展名为 .csv 的文件.

                  I have all the information to get the record already. I just don't see how to have PHP create the CSV file and let them download a file with a .csv extension.

                  推荐答案

                  试试:

                  header("Content-type: text/csv");
                  header("Content-Disposition: attachment; filename=file.csv");
                  header("Pragma: no-cache");
                  header("Expires: 0");
                  
                  echo "record1,record2,record3
                  ";
                  die;
                  

                  这是我用来选择性地对 CSV 字段进行编码的代码片段:

                  Here's a snippet of code I use to optionally encode CSV fields:

                  function maybeEncodeCSVField($string) {
                      if(strpos($string, ',') !== false || strpos($string, '"') !== false || strpos($string, "
                  ") !== false) {
                          $string = '"' . str_replace('"', '""', $string) . '"';
                      }
                      return $string;
                  }
                  

                  这篇关于在 PHP 中为用户创建一个 CSV 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何配置 php.ini 以使用 gmail 作为邮件服务器 下一篇:PHP file_get_contents() 和设置请求标头

                  相关文章

                2. <tfoot id='NAMQZ'></tfoot>
                  <i id='NAMQZ'><tr id='NAMQZ'><dt id='NAMQZ'><q id='NAMQZ'><span id='NAMQZ'><b id='NAMQZ'><form id='NAMQZ'><ins id='NAMQZ'></ins><ul id='NAMQZ'></ul><sub id='NAMQZ'></sub></form><legend id='NAMQZ'></legend><bdo id='NAMQZ'><pre id='NAMQZ'><center id='NAMQZ'></center></pre></bdo></b><th id='NAMQZ'></th></span></q></dt></tr></i><div id='NAMQZ'><tfoot id='NAMQZ'></tfoot><dl id='NAMQZ'><fieldset id='NAMQZ'></fieldset></dl></div>

                  <small id='NAMQZ'></small><noframes id='NAMQZ'>

                3. <legend id='NAMQZ'><style id='NAMQZ'><dir id='NAMQZ'><q id='NAMQZ'></q></dir></style></legend>
                    • <bdo id='NAMQZ'></bdo><ul id='NAMQZ'></ul>