B
B
Boris Belov2018-05-07 20:06:59
PHP
Boris Belov, 2018-05-07 20:06:59

How to configure the parser for XML unloading?

Task:
There is an upload export.admitad.com/ru/webmaster/websites/401730/pr...
It gives information in this form

<offer available="true" id="33697" type="vendor.model">
  <categoryId>26</categoryId>
  <currencyId>RUR</currencyId>
  <delivery>true</delivery>
  <description>Кожа, текстиль, резина</description>
  <manufacturer_warranty>true</manufacturer_warranty>
  <model>Кроссовки Puma Suede Big Sean</model>
  <modified_time>1525468937</modified_time>
  <name>Кроссовки Puma Suede Big Sean</name>
  <param name="Цвет">Серый</param>
  <param name="Размеры" unit="UK">7;7.5;8;8.5;9;9.5;10;10.5;11</param>
  <param name="Пол">Мужской</param>
  <pickup>true</pickup>
  <picture>https://www.basketshop.ru/files/catalog/33697/36625101(9).JPG</picture>
  <picture>https://www.basketshop.ru/files/catalog/33697/36625101(10).JPG</picture>
  <picture>https://www.basketshop.ru/files/catalog/33697/36625101(11).JPG</picture>
  <picture>https://www.basketshop.ru/files/catalog/33697/36625101(7).JPG</picture>
  <picture>https://www.basketshop.ru/files/catalog/33697/36625101(6).JPG</picture>
  <price>7490</price>
  <sales_notes>Предоплата или оплата наличными</sales_notes>
  <store>true</store>
  <url>https://ad.admitad.com/g/c36ced07fc3562130ecba5b05e1dda/?i=5&amp;ulp=https%3A%2F%2Fwww.basketshop.ru%2Fcatalog%2Fitem%2F33697%2F</url>
  <vendor>Puma</vendor>
  <vendorCode>36625101</vendorCode>
</offer>

Each product has an article (it is unique and given by the manufacturer. Almost all sellers adhere to them and give them in the unloading. It is called 36625101.
You need to display the name of the product, price, and a link to the product.
Now the parser simply searches for content according to the specified parameters for a certain positions:
<?php
include 'simple_html_dom.php'; 
//откуда будем парсить информацию
 $content = file_get_contents('http://export.admitad.com/ru/webmaster/websites/401730/products/export_adv_products/?user=solefinder&code=e867f6a1d2&feed_id=13560&format=xml');
// Определяем позицию строки, до которой нужно все отрезать
 $pos = strpos($content, '<offer available="true" id="33697" type="vendor.model">');
//Отрезаем все, что идет до нужной нам позиции
 $content = substr($content, $pos);
// Точно таким же образом находим позицию конечной строки
 $pos = strpos($content, '</offer>');
// Отрезаем нужное количество символов от нулевого
 $content = substr($content, 0, $pos);
//если в тексте встречается текст, который нам не нужен, вырезаем его
 $content = str_replace('','', $content);
// выводим спарсенный текст.
 echo $content;
 ?>

How I see it:
We take the article of the product, for example 36625101
Next, we look at whether it is available or not (parameter: )
If it is available, then display the name and price It should turn out
<div class="item clearfix">
<div class="img-wrap"><img src="<?php echo $picture; ?>" alt=""></div> <!-- изображение товара -->
<div class="title-link"><div class="title"><?php echo $name; ?></div></div> <!-- наименование товара -->
<div class="price-wrapper"><?php echo $price;?></div>  <!-- цена товара -->
<div class="btn-wrap"><a href="<?php echo $url; ?>">Купить</a> <!-- ссылка на товар товара -->
</div>
</div>

Question:
How to first search by article, based on this article, display information on the position?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan-s, 2018-05-07
@iborisbelov

Uh, use the XML parser
php.net/manual/en/refs.xml.php
https://www.w3schools.com/PHP/php_xml_simplexml_re...
XML is specially marked up data so that it can be easily parsed, manipulated. There are many libraries for this, it is not necessary to work with XML as a string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question