formulas xml to csv file conversion

Speed

New Member
Need help to add formula in php file and convert to csv file from xml data.Here is my construction data:XML File: \[code\]<PRODUCTS><PRODUCT code="012345" price="100"/><PRODUCT code="123456" price="200"/><PRODUCT code="123457" price="300"/><PRODUCTS/>\[/code\]Here is the PHP File:\[code\]<?php $filexml = 'price.xml'; if (file_exists($filexml)) { $xml = simplexml_load_file($filexml); $file = fopen('price.csv', 'w'); $header = array('code', 'price'); fputcsv($file, $header, ',', '"'); /** @var SimpleXMLElement $product */ foreach ($xml->PRODUCT as $product) { $value1 = $product->attributes()->code; $value2 = $product->attributes()->price; $formula = $value2 * 0.95; fputcsv($file, $value1, $formula, ',', '"'); } fclose($file); }?>\[/code\]The result need to be:CSV File:\[code\]code,price012345,95123456,190123457,285\[/code\]The problem is that my script is returning only the header.I will appreciate if anyone can help me to correct the issue.Thanks
 
Back
Top