我需要使用PHP循环和xmlwriter创建xml
文件。在行动中,我有两个foreach
循环:
$writer = new XMLWriter();
$writer->openMemory();
foreach ($nav as $k => $v) {
$writer->openURI($abspath . '/cache/xmls/news-' . $k . '.xml.gz');
$writer->startDocument('1.0', 'UTF-8');
$writer->setIndent(4);
$writer->startElement('urlset');
$writer->writeAttribute('xmlns', $xmlns);
foreach ($v as $k2 => $v2) {
$writer->startElement('url');
$writer->writeElement('loc', SITE . '/' . $v2);
$writer->writeElement('lastmod', '');
$writer->writeElement('changefreq', '');
$writer->writeElement('priority', '');
$writer->endElement();
$writer->flush();
}
$writer->endElement();
$writer->endDocument();
$writer->flush();
$writer->outputMemory();
}
我为每个循环添加Flush();
。
1-在操作中为每个循环添加flush()
是否为TRUE?或者我需要为所有循环添加一个flush();
?!
2 - 我添加openmemory();
这是Fulsh();
后的真实?