Examples of fgetcsv() function in php
The PHP fgetcsv() function is used to parse the CVS file in PHP program. Here you will see how you can do so. We need a CSV file and then after opening the file we can parse using the fgetcsv() function. Here is the details of fgetcsv() function.
Syntax of fgetcsv() Funtion in PHP Program
Array fgetcsv ( file_handler [, $length [, $delimiter [, $enclosure [, string $escape ]]]] )
CSV is a type of file. Its full form is Comma Separated Values.
In Excel files can be save as .csv.
These files opened in any text editor shows values as separated with comma.
In PHP csv file can be read and displayed the values using fgetcsv() function.
It can be achieve by using an file handler returned by fopen(), popen(), or fsockopen()) it parses each line with the CSV fields.
It returns the CSV fields in an array with each line.
Each array is containing the fields of each line.
It returns FALSE on failure and EOF.
Code for PHP fgetcsv() Function in PHP
$file1=fopen("c:/rose1/rose2.csv","r"); //Open the CSV file
while(($array1=fgetcsv($file1,1000,","))!==FALSE) //parse file in loop
echo " ".$array1[$x];
foreach ($array1 as $key=>$value)
echo " ".$value;
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.