PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php error_reporting(E_ALL); ini_set('display_errors', 'on'); $url = 'https://site.com/price.xml'; #$xml = simplexml_load_file($url); $url = <<<XML <?xml version='1.0' standalone='yes'?> <offers> <offer> <name>PHP: Behind the Parser</name> <stock_msk>5</stock_msk> <stock_msk_shops>5</stock_msk_shops> <offer> <name>PHP: Behind the Parser</name> <stock_msk>5</stock_msk> <stock_msk_shops>5</stock_msk_shops> </offer> </offers> XML; $xml = simplexml_load_string($url); var_dump($xml); $out = ''; $out .= '<?xml version="1.0" encoding="UTF-8"?>'."\n"; $out .= "<price>\n"; foreach ($xml->offers->offer as $offer) { $offer->name = htmlspecialchars($offer->name); $offer->stock_msk = preg_replace('/\+\d*/', '', $offer->stock_msk); $offer->stock_msk = (int)$offer->stock_msk + (int) $offer->stock_msk_shops; $out .= " <offer> <sku>$offer->code</sku> <name>$offer->name</name> <stock>$offer->stock_msk</stock> <price>$offer->retail_price</price> </offer>"; } $out .= "</price>\n"; #file_put_contents('price_new.xml', $out);
Show:  
Copy Clear