<?php 
function simplexml_load_file_curl($url) { 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $xml = simplexml_load_string(curl_exec($ch)); 
    return $xml; 
} 

$url = 'https://www.yntithalat.com/export/241943fd-9f4a-439a-bf71-63f2a313705f';
$xml = simplexml_load_file_curl($url); 
$veri = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; 
$veri .= ' <Urunler>'.PHP_EOL; 
foreach ($xml->product as $urun) { 

  
$variant = $urun->variants->variant;
$variantsay = count($variant);
  
for($i=0; $i < $variantsay; $i++){
  
  
$urun_kodu = $urun->variants->variant[$i]->barcode;
$renk = $urun->variants->variant[$i]->value1;
$urun_adi = $urun->name;
$aciklama = $urun->detail;
$urunstok= $urun->variants->variant[$i]->quantity;
$anakategori = $urun->category;
$Satfiyat = $urun->price;



$veri .=' <Urun>'.PHP_EOL; 
$veri .=' <UrunKodu><![CDATA[MX'.$urun_kodu.']]></UrunKodu>'.PHP_EOL; 
$veri .=' <UrunIsmi><![CDATA['.$urun_adi.' - '.$renk.']]></UrunIsmi>'.PHP_EOL; 
$veri .=' <Aciklama><![CDATA['.$aciklama.']]></Aciklama>'.PHP_EOL;
$veri .=' <ana_kategori><![CDATA['.$anakategori.']]></ana_kategori>'.PHP_EOL;
$veri .=' <Satfiyat>'.$Satfiyat.'</Satfiyat>'.PHP_EOL;
  $veri .=' <Skufiyat>'.$Satfiyat.'</Skufiyat>'.PHP_EOL;
$veri .=' <Marka>MobilMaxi</Marka>'.PHP_EOL;  
$veri .=' <Stok>'.$urunstok.'</Stok>'.PHP_EOL;

$resimler= $urun->variants->variant[$i]->images->image;
$resimsay = count($resimler);

for($j=0; $j < $resimsay; $j++){
    
    
    $ind=$j+1;
	$resim= $urun->variants->variant[$i]->images->image[$j];
	
	$veri .='<resim'.$ind.'>'.$resim.'</resim'.$ind.'>'.PHP_EOL;
    
    
    
}


$veri .=' </Urun>'.PHP_EOL; 
  
  
}  
  




 
} 
$veri .= '</Urunler>'; 

$file = "ynt.xml";
$fileOpen = fopen($file, 'w'); 
fwrite($fileOpen, $veri); 
fclose($fileOpen); 
echo "<h3> Xml Convert edildi.</h3>";
/*echo $veri;*/
?> 