title: Enclosing every field with double quotes in CSV file using PHP?
body: <p>I need to put all strings and number with double quotes in CSV file using PHP.</p>
  
  <p>How can I create CSV file from PHP in all data within double quotes ?</p>
  
  <p>I am using this code to generate CSV - I am using codeigniter framework</p>
  
  <pre><code>$array = array(
      array(
       (string)'XXX XX XX',
       (string)'3',
       (string)'68878353',
       (string)'',
       (string)'xxxx@xxxx.xxx.xx',
      ),
  );
  
  $this-&gt;load-&gt;helper('csv');
  array_to_csv($array, 'blueform.csv'); 
  </code></pre>
  
  <p><strong>Output I am getting:</strong></p>
  
  <pre><code>"XXX XX XX",3,68878353,,xxxx@xxxx.xxx.xx
  </code></pre>
  
  <p><strong>Expected Output:</strong></p>
  
  <pre><code>"XXX XX XX","3","68878353","","xxxx@xxxx.xxx.xx"
  </code></pre>
  
  <p><strong>Code of array_to_csv</strong></p>
  
  <pre><code>if (!function_exists('array_to_csv')) {
      function array_to_csv($array, $download = "") {
          if ($download != "") {   
              header('Content-Type: application/csv');
              header('Content-Disposition: attachement; filename="' . $download . '"');
          }
  
          ob_start();
          $f = fopen('php://output', 'w') or show_error("Can't open php://output");
          $n = 0;
          foreach ($array as $line) {
              $n++;
              if (!fputcsv($f, $line)) {
                  show_error("Can't write line $n: $line");
              }
          }
          fclose($f) or show_error("Can't close php://output");
          $str = ob_get_contents();
          ob_end_clean();
  
          if ($download == "") {
              return $str;
          } else {
              echo $str;
          }
      }
  }
  </code></pre>
  
  <p>Thank you in advance</p>