Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $fileXML = 'DOFQ89AlkJobBIlRJJDgQ6xyBEQllQniogFHwHd5.xml'; // Название файла
- $separator = '|'; // разделитель мултикеев
- $z = new XMLReader;
- $z->open($fileXML);
- $doc = new DOMDocument;
- // переходим к первому offer
- while ($z->read() && $z->name !== 'offer');
- // теперь на нужной глубине, переходим к следующему offer до конца древа
- while ($z->name === 'offer')
- {
- $node = new SimpleXMLElement($z->readOuterXML());
- $name = $node->name;
- $description = $node->description;
- $price = $node->price;
- $url = $node->url;
- $currency = $node->currencyId;
- $thumb = $node->thumbnail;
- $pictures_array = $node->original_picture; // $pictures_array = $node->picture;
- $badchar_fc = array ("\r","\t","\n"); // список плохих символов, которые нужно заменять на пробел.
- $description = str_ireplace($badchar_fc, ' ', $description);
- $description = preg_replace('! {2,}!u', ' ', $description); // чистка от лишних пробелов
- $fp = fopen("txt.txt", "a");
- fwrite($fp, "{$name}{$separator}{$description}{$separator}{$pictures_array}{$separator}{$url}\r\n"); // Если в 24 строке заменить на закомментированное, то здесь {$pictures_array[0]}
- fclose($fp);
- // к следующему <offer />
- $z->next('offer');
- }
Add Comment
Please, Sign In to add comment