troubleshooting Question

Need To Parse CSV file in PHP

Avatar of sharingsunshine
sharingsunshineFlag for United States of America asked on
PHPMac OS X
14 Comments1 Solution1023 ViewsLast Modified:
I have a csv file I am trying to parse two values out of it.  The first value is array element 1 productcode and the second value is element 4 weight.  After I get these two values for each product I need to create a csv file of the results using the implode function.

Here is the file
[PRODUCTS]
!PRODUCTID;!PRODUCTCODE;!PRODUCT;!CLEAN_URL;!WEIGHT;!LIST_PRICE;!DESCR;!FULLDESCR;!KEYWORDS;!TITLE_TAG;!META_KEYWORDS;!META_DESCRIPTION;!AVAIL;!RATING;!FORSALE;!SHIPPING_FREIGHT;!FREE_SHIPPING;!DISCOUNT_AVAIL;!MIN_AMOUNT;!LENGTH;!WIDTH;!HEIGHT;!LOW_AVAIL_LIMIT;!FREE_TAX;!CATEGORYID;!CATEGORY;!POS;!MEMBERSHIP;!PRICE;!TAXES;!ADD_DATE;!VIEWS_STATS;!SALES_STATS;!DEL_STATS;!SMALL_ITEM;!SEPARATE_BOX;!ITEMS_PER_BOX;!MANUFACTURERID;!MANUFACTURER
889;"10810-7";"";10810-7;0;75;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;50;;Wednesday 01 June 2011 02:03:18 AM;0;0;0;Y;N;1;"0";
888;"14553-4";"";14553-4;0;15;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;10;;Wednesday 01 June 2011 02:03:18 AM;0;0;0;Y;N;1;"0";
903;"150-6";"";150-6;0;14.050;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;9.350;;Wednesday 01 June 2011 02:03:35 AM;0;0;0;Y;N;1;"0";
902;"16343-9";"";16343-9;0;0;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;174.950;;Wednesday 01 June 2011 02:03:34 AM;0;0;0;Y;N;1;"0";
890;"166-7";"";166-7;0;14.950;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;9.950;;Wednesday 01 June 2011 02:03:20 AM;0;0;0;Y;N;1;"0";
906;"1672-1";"";1672-1;0;23.650;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;15.750;;Wednesday 01 June 2011 02:03:38 AM;0;0;0;Y;N;1;"0";
896;"1958-8";"";1958-8;0;168.750;"";"";"";"";"";"";0;0;N;0;N;Y;1;0;0;0;10;N;75;"ADD & ADHD";0;;115;;Wednesday 01 June 2011 02:03:31 AM;0;0;0;Y;N;1;"0";

Here is the code I am using to display the file and take it out of the csv format
<?php
$file = fopen("weight_nsp_ben.csv","r");
while(! feof($file))
  {
  print_r(fgetcsv($file));
  }
fclose($file);
?>

My problem is I am not sure how to extract productcode and weight for each product. As and indexed array it is index 1 and 4.  Thanks for the help.

Randal
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros