fgetcsv() is a PHP function which parses the line it reads for fields in CSV format and returns an array containing the fields read.
Questions tagged [fgetcsv]
491 questions
0
votes
2 answers
PHP fgetcsv with line ending character
I have an oddly-formatted file I need to parse with PHP. It uses ^ as the field delimiter, and ~ as the end-of-line character. I can easily set the $delimiter param of fgetcsv to ^ to get most of the data.
The problem is that fgetcsv doesn't accept…

user101289
- 9,888
- 15
- 81
- 148
0
votes
1 answer
Reading contents from text/csv document with inconsistencies in data
I am trying to import data from a source that is not a csv or txt but I am able to read it like a text / csv with my code.
The problem I am having is that some "data records" do not follow the same logic. I have approximately 70% of the document…

NotJay
- 3,919
- 5
- 38
- 62
0
votes
2 answers
Offsets of csv file when accessing through php?
I have a small doubt regarding the offsets. Suppose I have a csv file like this:
1
8 9 10 11 12 13 14
15 16 17 18 19 20
I am simply using fgetcsv function to retrieve data from csv to my php page. Here's the code:
$fp = FOPEN…

user3772084
- 31
- 2
0
votes
2 answers
Why is this PDO Insert executing twice?
This has been inserting each line from the csv into the database twice, and now today three times. Nothing else I put in the loop happens more than it should.
$file_handle = fopen("uploads/numbers.csv", "r");
$stmt = $db->prepare("INSERT INTO…

TestText
- 3
- 1
0
votes
0 answers
How to get fgetcsv to read UTF8 characters on Windows?
I am reading a Serbian UTF8 file with fgetcsv. While on linux
setlocale(LC_ALL,"sr_RS.UTF8")
does the trick, I couldn't get the characters to be loaded properly on Windows. Furthermore, when I try to save the string to the database, it saves only…

srgb
- 4,783
- 6
- 29
- 45
0
votes
4 answers
read the csv file column wise
I want to read the csv file column wise and get the every column data into specified array
[country]
Array(
[0]=>Australia
)
[city]
Array(
[0]=>vic
)

Ami Kamboj
- 105
- 1
- 10
0
votes
2 answers
How to process a CSV file with different enclosures
I am uploading a CSV file using fgetcsv() function . Now i encounter three cases as ==>
1) The CSV file is clean and contains no enclosures
--> ex : Name,Age,Address ..in this scenario , the file is processed properly and uploaded
2) The CSV…

user3134101
- 49
- 1
- 10
0
votes
0 answers
PHP performance tweak fgetcsv / array_filter
i'm
reading a csv file using fgetcsv
while (($data = (empty($this -> enclosure)) ? $method($fp, 10000, $this -> delimiter) : $method($fp, 10000, $this -> delimiter, $this -> enclosure)) !== FALSE)
push every line to an array
…

Informant
- 5
- 4
0
votes
4 answers
I am getting double output from a php loop
My data is outputting twice and I am not to sure why. It should be one fname and lname per line.

brad
- 870
- 2
- 13
- 38
0
votes
1 answer
PHP fgetcsv while search, multiple rows to array
I have a csv file in that i want to search in a specific column for a value, if found the corresponding row should be set in an array.
That i already have working, but if there are multiple rows that have that value, with my code only the last…

sharonna
- 35
- 3
0
votes
1 answer
Sanatise CSV content in PHP
I've built a bulk user import engine for my web application and it's working perfectly. I'm now sitting here asking myself, is it secure? After all, the content of this file is being pumped into my database!
Not being the wisest security nerd around…

Arbiter
- 486
- 1
- 8
- 21
0
votes
1 answer
php fgetcsv read date in different format
In csv cell contain date in format 31-Mar-90. Now If that csv created on Windows + MS Excel 2007, my php scripts shows in same format ie: 31-Mar-90 but if same date format added in csv that created on some other platform then php shows like: 31 Mar…

PHP Ferrari
- 15,754
- 27
- 83
- 149
0
votes
0 answers
Order events by date from CSV in PHP
I am trying to order by date DESC the events read from a CSV and print them in a DIV. The file has to be read till its end and then order by date DESC only the entries in the following categories: champions and euro.
This is the code I wrote,…

Mark
- 1,069
- 2
- 21
- 44
0
votes
0 answers
fgetcsv not reading mobile number columns
i am trying to upload a .csv file.. and at the same time inserting the data from csv to mysql fr this to work i have written this:
CONTROLLLER:
$file_path = './public/projects/mycsvfile.csv';
if (($handle = fopen($file_path, "r")) !== FALSE) {
…

Mohammed Sufian
- 1,743
- 6
- 35
- 62
0
votes
1 answer
PHP csv reader relationship within array
i have country list csv with its code i use below code to read the csv
function readCSV($csvFile){
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 1024);
}
…

Rakhi
- 929
- 15
- 41