- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to import csv file in PHP?
The below code can be used to import CSV file in PHP −
<?php $row = 1; if (($handle = fopen("name_of_file.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>
"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />
"; } } fclose($handle); } ?>
The file will display the contents of the csv file are displayed on the screen.
In the above code, beginning from row 1 (since row 0 would usually contain headers/column names), the csv file is opened in read mode and the fgetcsv function is called to read in 1000 rows of data present in the csv file.
The number of columns in every row is displayed along with the contents of it.
- Related Articles
- How to Export and import CSV file manually in PowerShell?
- How to import csv file data from Github in R?
- How to parse a CSV file using PHP
- How can we import data from .CSV file into MySQL table?
- How to read CSV file in Python?
- How to convert JSON file to CSV file using PowerShell?
- How to import a SVG file in JavaScript?
- How to write data to .csv file in Java?
- How to read data from .csv file in Java?
- How to create a CSV file manually in PowerShell?
- How to create a blank csv file in R?
- How to edit the CSV file using PowerShell?
- How to retrieve CSV file headers using PowerShell?
- How to save a Python Dictionary to CSV file?
- How to convert JSON to CSV file using PowerShell?

Advertisements