Press enter to see results or esc to cancel.

How to create a CSV file using PHP easily

In this video I have shown how to create a CSV file using PHP.
The example is shown with the help of XAMPP server installed in windows 10 PC.

The below code can be used to create a CSV file.

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=jinu.csv");
echo '"jinu","jawad","one","two"'."\n";
echo '"jinu","jawad","one","two"'."\n";;
echo '"jinu","jawad","one","two"'."\n";;
for ($x = 0; $x <= 100; $x++) {
echo '"'.$x.'","jinu","jawad"'."\n";

Output file will be downloaded from the browser for the user as below.



Leave a Comment