Creating csv file with php

0 votes

I want to make a CSV file, however, when I run the code, all that is produced is a blank page. I employ PHP 5. I employ the code below:

<?php
    $data = array ('aaa,bbb,ccc,dddd',
                   '123,456,789',
                   '"aaa","bbb"');

    $fp = fopen('data.csv', 'w');
    foreach($data as $line){
             $val = explode(",",$line);
             fputcsv($fp, $val);
    }
    fclose($fp);
?>

Can someone please help me with this?

Aug 1, 2022 in PHP by Kithuzzz
• 38,000 points
422 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to generate .json file with PHP?

Hello @kartik, Here is a sample code: <?php $sql="select ...READ MORE

answered Sep 15, 2020 in PHP by Niroj
• 82,840 points
2,791 views
0 votes
1 answer

How to create and download a csv file from php script?

Hello @kartik, You can use the built in fputcsv() for ...READ MORE

answered Oct 27, 2020 in PHP by Niroj
• 82,840 points
7,099 views
0 votes
1 answer

How to write CSV To File Without Enclosures In PHP?

Hello @kartik, The warnings about foregoing enclosures are ...READ MORE

answered Nov 9, 2020 in PHP by Niroj
• 82,840 points
4,301 views
0 votes
1 answer

How do I find the mime-type of a file with php?

Hello @kartik, mime_content_type() is deprecated, so you won't ...READ MORE

answered Nov 16, 2020 in PHP by Niroj
• 82,840 points
2,887 views
0 votes
0 answers

How can I parse a JSON file with PHP?

I want to parse a JSON file ...READ MORE

Jun 17, 2022 in PHP by narikkadan
• 63,600 points
435 views
0 votes
0 answers

Creating a config file in PHP

I am working on creating config file ...READ MORE

Jun 24, 2022 in PHP by narikkadan
• 63,600 points
390 views
0 votes
0 answers

How to parse a CSV file using PHP

I have a .csv file with the following content: ...READ MORE

Jul 28, 2022 in PHP by Kithuzzz
• 38,000 points
826 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,561 views
+1 vote
4 answers

How to write nested dictionaries to a CSV file

Using DictWriter there is no need in ...READ MORE

answered Oct 18, 2018 in Python by Richard William
27,736 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,401 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP