从PHP导出KML文件

从PHP导出KML文件,php,xml,laravel,character-encoding,kml,Php,Xml,Laravel,Character Encoding,Kml,在尝试用PHP动态创建KML文件(基本上只是XML)时,我遇到了一个奇怪的问题。我使用的是laravel框架,下面是生成KML文件的视图 <?php header('Content-type: text/plain'); header('Content-Disposition: attachment; filename="location.kml"'); ?> <?xml version='1.0' encoding='UTF-8'?> <kml x

在尝试用PHP动态创建KML文件(基本上只是XML)时,我遇到了一个奇怪的问题。我使用的是laravel框架,下面是生成KML文件的视图

<?php
    header('Content-type: text/plain');
    header('Content-Disposition: attachment; filename="location.kml"');
?>
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'>
  <Document>
    <name>Towers</name>

    <?php for ($i = 0; $i < count($points); $i++){ ?>
    <Placemark>
      <name>{{ $points[$i]['name'] }}</name>
      <!--HERE'S THE PROBLEM-->
      <styleUrl>#icon-503-DB4436-nodesc</styleUrl>
      <Point>
        <coordinates>{{ $points[$i]['coords'] }}</coordinates>
      </Point>
    </Placemark>
    <?php } ?>

    <?php for ($i = 0; $i < count($paths); $i++){ ?>
    <Placemark>
      <name>{{ $paths[$i]['name'] }}</name>
      <styleUrl>#line-000000-1-nodesc</styleUrl>
      <LineString>
        <tessellate>1</tessellate>
        <coordinates>{{ $paths[$i]['coords'] }}</coordinates>
      </LineString>
    </Placemark>
    <?php } ?>

    <Style id='icon-503-DB4436-nodesc-normal'>
      <IconStyle>
        <color>ff3644DB</color>
        <scale>1.1</scale>
        <Icon>
          <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href>
        </Icon>
        <hotSpot x='16' y='31' xunits='pixels' yunits='insetPixels'>
        </hotSpot>
      </IconStyle>
      <LabelStyle>
        <scale>0.0</scale>
      </LabelStyle>
      <BalloonStyle>
        <text><![CDATA[<h3>$[name]</h3>]]></text>
      </BalloonStyle>
    </Style>
    <Style id='icon-503-DB4436-nodesc-highlight'>
      <IconStyle>
        <color>ff3644DB</color>
        <scale>1.1</scale>
        <Icon>
          <href>http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png</href>
        </Icon>
        <hotSpot x='16' y='31' xunits='pixels' yunits='insetPixels'>
        </hotSpot>
      </IconStyle>
      <LabelStyle>
        <scale>1.1</scale>
      </LabelStyle>
      <BalloonStyle>
        <text><![CDATA[<h3>$[name]</h3>]]></text>
      </BalloonStyle>
    </Style>
    <StyleMap id='icon-503-DB4436-nodesc'>
      <Pair>
        <key>normal</key>
        <styleUrl>#icon-503-DB4436-nodesc-normal</styleUrl>
      </Pair>
      <Pair>
        <key>highlight</key>
        <styleUrl>#icon-503-DB4436-nodesc-highlight</styleUrl>
      </Pair>
    </StyleMap>
    <Style id='line-000000-1-nodesc-normal'>
      <LineStyle>
        <color>ff000000</color>
        <width>1</width>
      </LineStyle>
      <BalloonStyle>
        <text><![CDATA[<h3>$[name]</h3>]]></text>
      </BalloonStyle>
    </Style>
    <Style id='line-000000-1-nodesc-highlight'>
      <LineStyle>
        <color>ff000000</color>
        <width>2.0</width>
      </LineStyle>
      <BalloonStyle>
        <text><![CDATA[<h3>$[name]</h3>]]></text>
      </BalloonStyle>
    </Style>
    <StyleMap id='line-000000-1-nodesc'>
      <Pair>
        <key>normal</key>
        <styleUrl>#line-000000-1-nodesc-normal</styleUrl>
      </Pair>
      <Pair>
        <key>highlight</key>
        <styleUrl>#line-000000-1-nodesc-highlight</styleUrl>
      </Pair>
    </StyleMap>
  </Document>
</kml>
编辑2:


我尝试将
标记向上移动一点(虽然这在语法上是不正确的,但只是为了理解这个想法),只要它不是
标记的子项,它就可以正常工作。i、 e.在
标记之后放置它效果很好。

虽然不是理想的解决方案,但我通过放置一个额外的
echo'找到了一个解决方法。虽然不是理想的解决方案,但我通过放置一个额外的
echo'找到了一个解决方法。我能想到的唯一一件事是,您在刀片式解释器中触发了一个导致此问题的bug。我发现您在模板中只使用了一个刀片构造。尝试将其更改为php,并将模板另存为php文件而不是blade.php文件,看看这是否有帮助。谢谢@delatbabel,但它不起作用。它仍然在文件中显示
Url>
。好的,您发现了一个奇怪而奇妙的新bug。我想看看有没有时间可以复制一下。你下面的“解决方案”实际上只是引入了一个新的bug,它掩盖了现有的bug,但如果你必须这么做,那么我想你应该这么做。我能想到的唯一一件事是,你在刀片解释器中触发了一个bug,导致了这个bug。我发现您在模板中只使用了一个刀片构造。尝试将其更改为php,并将模板另存为php文件而不是blade.php文件,看看这是否有帮助。谢谢@delatbabel,但它不起作用。它仍然在文件中显示
Url>
。好的,您发现了一个奇怪而奇妙的新bug。我想看看有没有时间可以复制一下。您下面的“解决方案”实际上只是引入了一个新的bug,它掩盖了现有的bug,但是如果这是您必须要做的,那么我猜您应该这样做。
// $points
array(1) {
  [0]=>
  array(2) {
    ["name"]=>
    string(9) "Nijraj Gelani"
    ["coords"]=>
    string(29) "-79.58523260,43.73280100,0.0 "
  }
}
// $paths
array(0) {
}