Dynadot Black Friday and Cyber Monday 2026: save more on domains. See our sales.

Processing CSV files with PHP

SpaceshipSpaceship
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Watch

Ik

Quality //VIP Member
Impact
8
Hi guys,

I'm using fgetcsv() to read and process a CSV file. I get no errors, but it seems that for certain data PHP saves 2 or 3 CSV cells into a single array cell!!!! so I get line[12] for example as NULL!

Any idea? could that be caused by double-quotes or long numbers?? Not sure

Thanks

My code
Code:
<?php require('config.php'); ?>

<?php
$csvfile = fopen($dataPath, "r");

while (!feof($csvfile)){
	$line = fgetcsv($csvfile, 1024, ',');
	$active = $line[0];
	$title = $line[1];
	$image = $line[2];
	$man = $line[3];
	$descriptions = $line[4];
	$descriptionl = $line[5];
	// etc...............
	$cost = $line[20];
		
	echo $man . "<br />";
}

fclose($csvfile);
?>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
You need to look at the raw source file but I think you've answered the question.

PS: if you need to process large files there may be alternatives. For example if you have access to the shell command you could use the Linux 'cut' command. LOAD DATA INFILE is also useful if you want to import the file into a mySQL DB.
 
0
Close
You need to look at the raw source file but I think you've answered the question.

PS: if you need to process large files there may be alternatives. For example if you have access to the shell command you could use the Linux 'cut' command. LOAD DATA INFILE is also useful if you want to import the file into a mySQL DB.

Thanks mate,

I figured it out; it was the length parameter in the fgetcsv() function. It was too short.

Thanks again
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

New: watch any domain
You can now watch domains on NamePros. We check each one and notify you when something changes. Search for a domain and press Watch on...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back