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","[email protected]"),
    array("2","Jane","Foe","[email protected]"),
    array("3","Mane","Poe","[email protected]"),
    array("4","Tane","Koe","[email protected]"),
    array("5","Pane","Roe","[email protected]"),
);
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