Jump to content

selvakumar

New Members
  • Posts

    5
  • Joined

  • Last visited

selvakumar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @Barand I am little bit curious that you shown the desired result. But when I used your logic in my code. It failed function generateCSV($data, $filename) { $fp = fopen("/local/myloc/populated/".$filename,"w+"); foreach ($data as $k => $v) { if ($k==0) { fputcsv($fp, array_keys($v)); } fprintf($fp, '"%s","%s","%s","%s","%s","%s"'."\n",array_values($v)); } fclose($fp); } I made only 2 changes. 1) path .. i don't think any issue 2) removed 3 dots before array_vales. If i keep that one, my report fails to run. Overall my report runs without any error. Logs generated. But CSV failed to generate
  2. @gw1500se Yes. I want. I really don't know why my tester insist this. There is no issue in values. Only in format double quotation
  3. Thanks gw1500se/Barand @gw1500se $fields[$k] = "\"".$v."\""; It doesn't provide desired result Date,time,Device,label,throughput_read,throughput_write """11/21/2020""","""00:00""","""audigysg36s6101""","""192905199.0""","""1742118968.0""","""11.073020990149""","""97.584""" """11/21/2020""","""00:05""","""audigysg36s6101""","""192914200.0""","""1742253920.0""","""11.072679922568""","""97.559""" @Barand I tried to apply your logic, but no luck . I am not sure why it failed to me function generateCSV($data, $filename) { $fp = = fopen("/local/myloc/populated/".$filename,"w+"); foreach ($data as $k => $v) { if( $k === 0 ) { fputcsv($fp, array_keys($v)); // First write the headers } fprintf($fp, '"%s","%s","%s","%s","%s","%s"'."\n",array_keys($v)); } fclose($fp); } head -20 -v 2020_11_22_SERVER.CSV ==> 2020_11_22_SERVER.CSV <== Date,time,Device,label,throughput_read,throughput_write No Rows
  4. Thank you very much gw1500se . I somewhat messed up the question. Actually i want to create a file on CSV format. Below is my logic to achieve my goal if($generate_csv){ generateCSV($custom[0]['details'], date('Y_m_d_')."check".".CSV", $detail_headers); } function generateCSV($data, $filename) { $file = fopen("/local/myloc/populated/".$filename,"w+"); $i = 0; foreach ($data as $line) { $fields = array(); foreach ($line as $k => $v) { $fields[$k] = $v; } if( $i === 0 ) { fputcsv($file, array_keys($fields) ); // First write the headers } fputcsv($file, array_values($fields)); $i++; } fclose($file); } There is no issue in my output Date,time,Device,lable,throughput_read,throughput_write 11/21/2020,00:00,audigysg36s6101,192905199.0,1742118968.0,11.073020990149,97.584 11/21/2020,00:05,audigysg36s6101,192914200.0,1742253920.0,11.072679922568,97.559 But i need to show every value in double quotes like "11/21/2020,00:00","audigysg36s6101","192905199.0","1742118968.0","11.073020990149","97.584" to get above output, i changed my code $fields[$k] = $v. ' '; Now i got one blank space in at the end of each value like "11/21/2020,00:00 ","audigysg36s6101 ","192905199.0 ","1742118968.0 ","11.073020990149 ","97.584 " If i use trim then it removes all double quotes in the line that i don't need. 11/21/2020,00:00,audigysg36s6101,192905199.0,1742118968.0,11.073020990149,97.584 Input values to get csv [1] => Array ( [Date] => 11/21/2020 [time] => 00:00 [Device] => audigysg36s6101 [lable] => 192905199.0 [throughput_read] => 1742118968.0 [throughput_write] => 11.073020990149 ) [1] => Array ( [Date] => 11/21/2020 [time] => 00:15 [Device] => audigysg36s6101 [lable] => 192914200.0 [throughput_read] => 1742253920.0 [throughput_write] => 11.072679922568 )
  5. Team I tried to create csv output ( every value in double quotes) in my php using below function if($generate_csv){ generateCSV($custom[0]['details'], date('Y_m_d_')."check".".CSV", $detail_headers); } function generateCSV($data, $filename) { $file = fopen("/local/myloc/populated/".$filename,"w+"); $i = 0; foreach ($data as $line) { $fields = array(); foreach ($line as $k => $v) { $fields[$k] = $v; } if( $i === 0 ) { fputcsv($file, array_keys($fields) ); // First write the headers } fputcsv($file, array_values($fields)); $i++; } fclose($file); } I got below output with one issue (There is a blank at the end of each value) Date,time,Device,lable,throughput_read,throughput_write "11/19/2020 ","00:00 ","audigysg36s6101 ","host17 ","0,00 ","0,00 " "11/19/2020 ","00:00 ","audigysg36s6101 ","host1 ","0,00 ","0,00 " "11/19/2020 ","00:00 ","audigysg36s6101 ","host18 ","0,00 ","0,00 " Could you please help me to resolve this issue
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.