CCTV节目表生成XML文件 - 使用PHP curl_multi获取数据
formatOutput = true;
// 创建根节点
$tv = $xml->createElement('tv');
$tv->setAttribute('generator-info-name', 'Sage');
$tv->setAttribute('generator-info-url', 'https://github.com/OpenAI/gpt/blob/main/samples/dialogue.py');
// 遍历接口1数据生成XML节点
foreach ($ch1_data[0]['ret_data'] as $ch1_item) {
$channel = $xml->createElement('channel');
$channel->setAttribute('id', $ch1_item['bd_name']);
$displayName = $xml->createElement('display-name');
$displayName->setAttribute('lang', 'zh');
$displayName->nodeValue = $ch1_item['bd_name'];
$channel->appendChild($displayName);
$programme1 = $xml->createElement('programme');
$programme1->setAttribute('channel', $ch1_item['bd_name']);
$programme1->setAttribute('start', str_replace('-', '', str_replace(':', '', substr($ch1_item['begin_time'], 0, 19))) . ' +0800');
$programme1->setAttribute('stop', str_replace('-', '', str_replace(':', '', substr($ch1_item['end_time'], 0, 19))) . ' +0800');
$title1 = $xml->createElement('title');
$title1->setAttribute('lang', 'zh');
$title1->nodeValue = $ch1_item['desc'];
$programme1->appendChild($title1);
$tv->appendChild($channel);
$tv->appendChild($programme1);
}
// 遍历接口2数据生成XML节点
foreach ($ch2_data[0]['ret_data'] as $ch2_item) {
$channel = $xml->createElement('channel');
$channel->setAttribute('id', $ch2_item['bd_name']);
$displayName = $xml->createElement('display-name');
$displayName->setAttribute('lang', 'zh');
$displayName->nodeValue = $ch2_item['bd_name'];
$channel->appendChild($displayName);
$programme2 = $xml->createElement('programme');
$programme2->setAttribute('channel', $ch2_item['bd_name']);
$programme2->setAttribute('start', str_replace('-', '', str_replace(':', '', substr($ch2_item['begin_time'], 0, 19))) . ' +0800');
$programme2->setAttribute('stop', str_replace('-', '', str_replace(':', '', substr($ch2_item['end_time'], 0, 19))) . ' +0800');
$title2 = $xml->createElement('title');
$title2->setAttribute('lang', 'zh');
$title2->nodeValue = $ch2_item['desc'];
$programme2->appendChild($title2);
$tv->appendChild($channel);
$tv->appendChild($programme2);
}
$xml->appendChild($tv);
// 保存XML文件
$xml->save('tv.xml');
?>
原文地址: https://www.cveoy.top/t/topic/qAv0 著作权归作者所有。请勿转载和采集!