PHP   

Create new CSV file using PHP

Please feel free to use this short PHP code snippet to create CSV files for your project needs. Don’t forget to change our static data array with your dynamic array.

$leads = array(
    array("id","first_name","last_name","email"),
    array("1","John","Doe","johndoe@example.com"),
    array("2","Jane","Foe","jandoe@example.com"),
    array("3","Mane","Poe","manepoe@example.com"),
    array("4","Tane","Koe","tanekoe@example.com"),
    array("5","Pane","Roe","paneroe@example.com"),
);
if(!empty($leads)){
    $file = fopen($_SERVER["DOCUMENT_ROOT"]."/files/leads.csv","w");
    foreach ($leads as $line) {
        fputcsv($file, $line);
    }
    fclose($file);
}
Need a helping hand in fixing your website issues?

If you are facing any problems in implementing these code snippets and tutorials, you can hire us to fix your website issues.

Hire Us