I need help, I do a simple analysis of xml in the price list in CSV to synchronize the store, or rather I study and want to do it. The task of the script is to take xml, download and make a CSV from it in the specified format. Please do not pay attention to the correctness of this whole matter (in terms of writing). Actually, there is a problem with outputting a string with dimensions (options), they need to be converted to a specific format for loading, which I did. But when writing via fputcsv () to a file, they are added a separator (comma or semicolon, which I put), but here the separator is not needed, they must be a string with a transfer and not an array. Accordingly, later csv understands this as separate columns. enter image description here

In fact, they need to be written without separators in a single column. My processing code:

<?php $filepo= file_get_contents('http://free-run.kiev.ua/yml/12345'); file_put_contents('down.xml', $filepo); $filexml= 'down.xml'; if (file_exists($filexml)) { $xml = simplexml_load_file($filexml); $i = 1; // Position counter $values = []; // PHP array // Writing column headers $columns = array('url', '_CUSTOM_BASE_PRICE_', '_CUSTOM_BASE_CURRENCY_CODE_', 'categoryId', 'picture', 'delivery', 'name', 'description', '_OPTION_','_OPTION2_'); $fs = fopen('synchro.csv', 'w'); fputcsv($fs, $columns, ';'); fclose($fs); // Iterate through each <item> node $node = $xml->xpath('//offer'); foreach ($node as $n) { // Iterate through each child of <item> node $child = $xml->xpath('//offer['.$i.']/*'); foreach ($child as $value) { $values[] = $value; } $pere = "\n"; $razmery = $n->param; $pieces = explode(',', $razmery); foreach ($pieces as $value2) { $values[] = 'radio|Размер|' .$value2. '|1|100|0|+|0.0000|+|0|+|0.00' .$pere; } // Write to CSV files (appending to column headers) $fs = fopen('synchro.csv', 'a'); fputcsv($fs, $values, ';'); fclose($fs); $values = []; // Clean out array for next <item> (ie, row) $values2 = []; // Clean out array for next <item> (ie, row) $i++; // Move to next <item> (ie, node position) } } 
  • if the separator is not needed, then do not use fputcsv , but what’s the problem? - teran
  • I looked carefully, and there this data was in an array, transformed into a troc, and it almost got to work as it should. But thanks for the answer thanks! - Bogdan Novik

0