how to read csv file in php
![]() |
how to read csv file in php |
After Learning You can Read any CSV file using php..you can also insert csv data into mysql..
Create CSV file called:
1. user.csv
1 2 3 4 5 6 | "ANJAN KUMAR","Anjankumardhali6@gmail.com","Dept. of Physics" "Ratul Bain","ratul85@gmail.com","Computer Science" "Bonna","Bonna53@gmail.com","Software Engineer" "Rasel","rasel53@yahoo.com","Computer Programmer" "David Malan","David54@hotmail.com","Android Developer" "Kate","kate22@mail.com","Computer Engineer" |
Now create a readcsv.php file to read csv data from user.csv file copy the below codes and save it..
2. readcsv.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <html> <head> <title>PHP Read csv file</title> <style> table { border-collapse: collapse; width: 50%; font-family:verdana; } th, td { padding: 8px; } tr:nth-child(even){background-color: #f2f2f2} th { background-color: #4CAF50; color: white; } </style> </head> <body> <?php $CSVfp = fopen ( "user.csv" , "r" ); if ( $CSVfp !== FALSE) { ?> <table> <tr> <th>Name</th> <th>Email</th> <th>Department</th> </tr> <?php while (! feof ( $CSVfp )) { $data = fgetcsv ( $CSVfp , 1000, "," ); ?> <tr> <td><?php echo $data [0]; ?></td> <td><?php echo $data [1]; ?></td> <td><?php echo $data [2];?></td> </tr> <?php } ?> </table> <?php } fclose( $CSVfp ); ?> </body> </html> |
That's it Friends how to read csv file in php..if you like This post please share with Your Friends..Thank You...
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.