NameSilo

Processing CSV files with PHP

SpaceshipSpaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
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
•••
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
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Payment Flexibility
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back