<?php
$xml = new SimpleXmlElement(<<<XML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE yml_catalog SYSTEM "shops.dtd">
<yml_catalog>
</yml_catalog>
XML
);
$xml->addAttribute('date', (new DateTimeImmutable())->format('Y-m-d H:i'));
print $xml->asXML();
// <?xml version="1.0" encoding="utf-8"?>
// <!DOCTYPE yml_catalog SYSTEM "shops.dtd">
// <yml_catalog date="2024-01-24 16:42">
// </yml_catalog>
Сервер предоставляет ответ в фоматах xml или json, в зависимости от значения заголовка “Accept” клиента. Возможные значения:
application/xml
application/json
$data = [];
while ($z->name === 'offer') {
...
$data[] = '("'.$id.'","'.htmlspecialchars(urldecode($url)).'","'.$today.'",'.(int)$price.')';
if (count($data) > 99) {
$sql = 'INSERT INTO `products` (`id`,`url`,`date`,`price`) VALUES '
. implode(',', $data)
. 'ON DUPLICATE KEY UPDATE `url` = VALUES(`url`), `price` = VALUES(`price`)';
mysqli_query($link6,$sql);
$data = [];
}
...
}
if (count($data) > 0) {
$sql = 'INSERT INTO `products` (`id`,`url`,`date`,`price`) VALUES '
. implode(',', $data)
. 'ON DUPLICATE KEY UPDATE `url` = VALUES(`url`), `price` = VALUES(`price`)';
mysqli_query($link6,$sql);
}
<items>
<item>...</item>
<item>...</item>
</items>