php - Parsing CSV strings to multiple-dimensional array -


i'm getting following data , need able use php put data multi-dimensional array can use data variables later on...

'ordernumber,orderdate,orderstatus,purchasedwebsite,paymentmethod,shippingmethod,subtotal,shippingcost,grandtotal,totaltax,totalpaid,totalrefunded,itemname,itemsku,itemisbn,itemstock,itemprice,costprice,itemordered,iteminvoiced,itemsent,customerid,billingfirstname,billinglastname,billingcompany,billinge-mail,billingphone,billingaddress1,billingaddress2,billingcity,billingpostcode,billingstate,billingcountry,shippingfirstname,shippinglastname,shippingcompany,shippinge-mail,shippingphone,shippingaddress1,shippingaddress2,shippingcity,shippingpostcode,shippingstate,shippingcountry,vendor sku,line code  "100000002","02/10/2013","pending","main website - main website store - default store view","checkmo","flatrate_flatrate","2.0000","10.0000","12.0000","0.0000","","","k&n air filter wrap","ya-6504pk k&n","","","1.0000","","1.0000","0.0000","0.0000","1","brian","","","","","","","sunrise","33323","florida","us","brian","","","","","","","sunrise","33323","florida","us","","",  "100000002","02/10/2013","pending","main website - main website store - default store view","checkmo","flatrate_flatrate","2.0000","10.0000","12.0000","0.0000","","","k&n air filter wrap","ya-6601-tdk k&n","","","1.0000","","1.0000","0.0000","0.0000","1","brian","","","","","","","sunrise","33323","florida","us","brian","","","","","","","sunrise","33323","florida","us","","",  "100000003","07/10/2013","pending","main website - main website store - default store view","checkmo","flatrate_flatrate","1716.5000","5.0000","1721.5000","0.0000","","","cardone high pressure diesel injection oil pump","2p-225 cardone","","","1716.5019","","1.0000","0.0000","0.0000","1","brian","","","","","","","sunrise","33323","florida","us","brian","","","","","","","sunrise","33323","florida","us","2p-225","a1",  ' 

i've been toying around different php functions make happen data. don't have in file while examples open file data, don't have available file rather these strings. know i'll need use foreach loop done, have had no success in doing correctly far.

i've tried following code values weren't showing odd reason...

$lines = explode("\n", $filecontent); $formatting = explode(",", $lines[0]); unset($lines[0]); $results = array(); foreach ( $lines $line ) {    $parsedline = str_getcsv( $line, ',' );    $result = array();    foreach ( $formatting $index => $caption ) {       if(isset($parsedline[$index])) {          $result[$formatting[$index]] = trim($parsedline[$index]);       } else {          $result[$formatting[$index]] = '';       }    }    $results[] = $result; } 

any appreciated!


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -