convert specified value on array from xml to csv in php

good man

New Member
i want to convert to csv from xml file only the specified values...XML File:\[code\]<?xml version="1.0" encoding="UTF-8"?><file><PRODUCT sku="12345" price="129"/><PRODUCT sku="12356" price="150"/><PRODUCT sku="12367" price="160"/><PRODUCT sku="12389" price="190"/></file>\[/code\]CSV File.SKU,PRICE12345,12912356,15012367,16012389,190but i want to get the price only for 12345, 12367 and 12389This is my start file:\[code\] <?php $filexml = 'file.xml'; if (file_exists($filexml)){ $xml = simplexml_load_file($filexml); $file = fopen('file.csv', 'w'); $header = array('sku', 'price'); fputcsv($file, $header, ',', '"'); foreach ($xml->PRODUCT as $product){ $item = array(); $value1 = $product->attributes()->sku; $value2 = $product->attributes()->price; $item[] = $value1; $item[] = $value2; fputcsv($file, $item, ',', '"'); } fclose($file); } ?>\[/code\]an option can be this, but is returning me Array, maybe is wrong something there.\[code\]<?php $filexml = 'file.xml'; if (file_exists($filexml)){ $xml = simplexml_load_file($filexml); $file = fopen('file.csv', 'w'); $header = array('sku', 'price'); $customvalue = http://stackoverflow.com/questions/12780671/array('12345', '12367', '12389'); fputcsv($file, $header, ',', '"'); foreach ($xml->PRODUCT as $product){ $item = array(); $value1 = $product->attributes()->sku; $value2 = $product->attributes()->price; $item[] = $customvalue; $item[] = $value2; fputcsv($file, $item, ',', '"'); } fclose($file); } ?>\[/code\]Thanks
 
Back
Top