使用PHP

时间:2015-08-26 19:17:43

标签: php xml

我需要使用此文本文件http://gis.fcd.maricopa.gov/apps/forecastzone/wxlabels.txt并使用php导出xml文件。我有这个导出xml的当前代码,但我需要一个不同的格式

<?php

date_default_timezone_set("MST"); //or whatever your default timezone is.
header("Content-Type: text/xml"); 

$fp = fopen('http://gis.fcd.maricopa.gov/apps/forecastzone/wxlabels.txt', 'r');

$xml = new XMLWriter;
$xml->openURI('php://output');
$xml->startDocument(); 
$xml->setIndent(true); // makes output cleaner

$xml->startElement('messages'); 

while ($line = fgetcsv($fp)) {

   $xml->startElement('zones');
   $xml->writeElement('name', $line[0]);
   $xml->writeElement('times', $line[1]);
   $xml->endElement();
}

$xml->endElement();

?>

它导出到http://alert.fcd.maricopa.gov/alert/Google/v3/php/msp.php,如下所示:

<messages>
<zones>
<name>Gila Bend</name>
<times>2:00pm-5:00pm</times>
</zones>
</messages>

我需要它看起来像这样:

<messages>
<zones name="Gila Bend" times="2:00pm-5:00pm"</zones>
</messages>

我需要在我的php文件中添加/编辑什么?

0 个答案:

没有答案