Я хочу извлечь только несколько столбцов из моего CSV и игнорировать остальные из них Вот CSV со всеми столбцами
part_number_key,buy_button_rank,category_id,id,brand,vendor_category_id,name,part_number,sale_price,currency,description,url,warranty,general_stock,weight,status,recommended_price,images,characteristics,attachments,vat_id,family,start_date,estimated_stock,reversible_vat_charging,min_sale_price,max_sale_price,offer_details,offer_properties,product_measurements,availability,stock,handling_time,barcode,ean,commission,validation_status,offer_validation_status,ownership,best_offer_sale_price,best_offer_recommended_price,number_of_offers
DASDSA,1,11,123,brand,,Name,"part number",12.31,RON,description,https://www.url.com,12,10,0,1,12.19,"a:3:{i:0;a:2:{s:3:""url"";s:27:""https://url.com/images.jpg1"";s:12:""display_type"";i:1;}i:1;a:2:{s:3:""url"";s:27:""https://url.com/images.jpg2"";s:12:""display_type"";i:0;}i:2;a:2:{s:3:""url"";s:27:""https://url.com/images.jpg3"";s:12:""display_type"";i:0;}}","a:11:{i:0;a:2:{s:2:""id"";i:8937;s:5:""value"";s:5:""value"";}i:1;a:2:{s:2:""id"";i:8930;s:5:""value"";s:5:""value"";}i:2;a:2:{s:2:""id"";i:8927;s:5:""value"";s:5:""value"";}i:3;a:2:{s:2:""id"";i:8928;s:5:""value"";s:5:""value"";}i:4;a:2:{s:2:""id"";i:5537;s:5:""value"";s:5:""value"";}i:5;a:2:{s:2:""id"";i:8932;s:5:""value"";s:5:""value"";}i:6;a:2:{s:2:""id"";i:8934;s:5:""value"";s:5:""value"";}i:7;a:2:{s:2:""id"";i:8929;s:5:""value"";s:5:""value"";}i:8;a:2:{s:2:""id"";i:7235;s:5:""value"";s:5:""value"";}i:9;a:2:{s:2:""id"";i:6556;s:5:""value"";s:5:""value"";}i:10;a:2:{s:2:""id"";i:5401;s:5:""value"";s:5:""value"";}}",a:0:{},1,"a:3:{s:2:""id"";i:1104;s:4:""name"";s:4:""NAME"";s:14:""family_type_id"";i:244;}",a:0:{},10,,11,200,"a:3:{s:2:""id"";i:2484194;s:13:""warranty_type"";N;s:16:""supply_lead_time"";i:14;}",a:0:{},a:0:{},"a:1:{i:0;a:2:{s:12:""warehouse_id"";i:1;s:2:""id"";i:3;}}","a:1:{i:0;a:2:{s:12:""warehouse_id"";i:1;s:5:""value"";i:10;}}","a:1:{i:0;a:2:{s:12:""warehouse_id"";i:1;s:5:""value"";i:0;}}",a:0:{},a:0:{},"a:5:{s:5:""value"";s:7:""20.0000"";s:4:""type"";s:10:""percentage"";s:2:""id"";s:3:""123"";s:8:""priority"";s:1:""4"";s:7:""created"";s:19:""2010-01-16 11:25:02"";}","a:1:{i:0;a:3:{s:5:""value"";i:9;s:11:""description"";s:22:""Approved documentation"";s:6:""errors"";N;}}","a:3:{s:5:""value"";i:1;s:11:""description"";s:8:""Saleable"";s:6:""errors"";N;}",1,11,11,1
D3129DKQW,1,456,123,Bluedio,,name,"part number",123,EUR,description,https://url.com,24,1,0,1,12,"a:3:{i:0;a:2:{s:3:""url"";s:27:""https://url.com/images.jpg1"";s:12:""display_type"";i:1;}i:1;a:2:{s:3:""url"";s:27:""https://url.com/images.jpg2"";s:12:""display_type"";i:0;}i:2;a:2:{s:3:""url"";s:27:""https://url.com/images.jpg3"";s:12:""display_type"";i:0;}}","a:14:{i:0;a:2:{s:2:""id"";i:7774;s:5:""value"";s:3:""val"";}i:1;a:2:{s:2:""id"";i:7947;s:5:""value"";s:3:""val"";}i:2;a:2:{s:2:""id"";i:8001;s:5:""value"";s:3:""val"";}i:3;a:2:{s:2:""id"";i:8937;s:5:""value"";s:3:""val"";}i:4;a:2:{s:2:""id"";i:8930;s:5:""value"";s:3:""val"";}i:5;a:2:{s:2:""id"";i:8927;s:5:""value"";s:3:""val"";}i:6;a:2:{s:2:""id"";i:8928;s:5:""value"";s:3:""val"";}i:7;a:2:{s:2:""id"";i:5537;s:5:""value"";s:3:""val"";}i:8;a:2:{s:2:""id"";i:8932;s:5:""value"";s:3:""val"";}i:9;a:2:{s:2:""id"";i:8934;s:5:""value"";s:3:""val"";}i:10;a:2:{s:2:""id"";i:8929;s:5:""value"";s:3:""val"";}i:11;a:2:{s:2:""id"";i:7235;s:5:""value"";s:3:""val"";}i:12;a:2:{s:2:""id"";i:6556;s:5:""value"";s:3:""val"";}i:13;a:2:{s:2:""id"";i:5401;s:5:""value"";s:3:""val"";}}",a:0:{},1,"a:3:{s:2:""id"";i:123456;s:4:""name"";s:4:""Name"";s:14:""family_type_id"";i:244;}",a:0:{},144,,11,200,"a:3:{s:2:""id"";i:242414;s:13:""warranty_type"";N;s:16:""supply_lead_time"";i:14;}",a:0:{},a:0:{},"a:1:{i:0;a:2:{s:12:""warehouse_id"";i:1;s:2:""id"";i:3;}}","a:1:{i:0;a:2:{s:12:""warehouse_id"";i:1;s:5:""value"";i:9;}}","a:1:{i:0;a:2:{s:12:""warehouse_id"";i:1;s:5:""value"";i:0;}}",a:0:{},a:0:{},"a:5:{s:5:""value"";s:7:""20.0000"";s:4:""type"";s:10:""percentage"";s:2:""id"";s:5:""12492"";s:8:""priority"";s:1:""4"";s:7:""created"";s:19:""2010-01-16 11:25:02"";}","a:1:{i:0;a:3:{s:5:""value"";i:9;s:11:""description"";s:22:""Approved documentation"";s:6:""errors"";N;}}","a:3:{s:5:""value"";i:1;s:11:""description"";s:8:""Saleable"";s:6:""errors"";N;}",1,77.31,83.19,1
Вот код PHP
$handle = fopen("feed.csv", "r");
$columns = array(11, 7, 11, 9, 14, 5, 3, 18);
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo("<tr>\r\n");
foreach ($data as $index=>$val) {
if (in_array($index+1, $columns)) {
echo("\t<td>$val</td>\r\n");
}
}
echo("</tr>\r\n");
}
проблема в выводе, вывод без запятых (разделителя) или строки разрыва, и это не является допустимым CSV и как я могу переписать CSV с помощью fputcsv ();в этом случае?
Спасибо!