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
"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
<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.