Skip to content

Instantly share code, notes, and snippets.

@srsad
Last active March 19, 2018 10:40
Show Gist options
  • Save srsad/b6beac3b07908b81ac15e07e04d3a25d to your computer and use it in GitHub Desktop.
Save srsad/b6beac3b07908b81ac15e07e04d3a25d to your computer and use it in GitHub Desktop.
<?php
$url = 'http://feed.com/export/main/database/?data=objects&format=yandex&v=yandex&key=link_feed=xml';
$file = MODX_ASSETS_PATH.'components/name/file/filename.xml';
if (!copy($url, $file)) {
echo "не удалось скопировать $file...\n";
}
$xml = new XMLReader();
$doc = new DOMDocument;
$i = 1;
$limit = 30;
$offset = 5;
$xml->open( $file );
while( $xml->read() ) {
if( 'offer' === $xml->name ) {
if($i > 1){ $xml->next(); }
if($i === 1 && $offset !== 0){
for($j = 1; $j <= $offset; $j++){
$xml->next();
}
}
$node = simplexml_import_dom($doc->importNode($xml->expand(), true));
$array = json_decode(json_encode((array)$node), true);
$internal_id = $xml->getAttribute('internal-id');
echo $internal_id.'<br>';
$product[$internal_id]['internal_id'] = $internal_id;
$product[$internal_id] = $array;
$product[$internal_id]['description'] = (string)$node->{'description'};
if($i >= $limit){ break; }
$i++;
}
}
print_r($product);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment