使用标记从PHP生成xml

时间:2021-09-22 15:43:12

I am trying to generate the following xml code using php:

我试图使用PHP生成以下xml代码:

http://dpaste.com/708476 (now broken)

http://dpaste.com/708476(现已破)

I tried to do this in many several ways, but why is the output always without any tags ???? i want it to be the same exact format as he xml file and with all the tags ... here is what i get when i tried to output it:

我尝试过很多种方法,但为什么输出总是没有任何标签????我希望它与xml文件和所有标签具有相同的格式......这是我在尝试输出时得到的结果:

2 834 SE LAMBERT CIRCLE 45.490943 -122.406561 834 SE LAMBERT ST 45.468602 -122.657627 

Does anyone have any idea what should I do?

有谁知道我该怎么办?

2 个解决方案

#1


1  

Make sure you are outputting the first line in an echo statement or similar:

确保输出echo语句中的第一行或类似内容:

<?php
echo "<?xml version=\"1.0\"?>";
?>
//rest of XML

If you just have <?xml... (outside of PHP tags) as the first line, PHP will think you are trying to use an (undefined) constant xml

如果您只有<?xml ...(在PHP标记之外)作为第一行,PHP会认为您正在尝试使用(未定义的)常量xml

#2


0  

<?php header('Content-type:text/xml;charset=UTF-8'); ?>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<geocoderResults>
  <count>2</count>
  <results>
    <result>
      <description>834 SE LAMBERT CIRCLE</description>
      <lat>45.490943</lat>
      <lng>-122.406561</lng>
    </result>
    <result>
      <description>834 SE LAMBERT ST</description>
      <lat>45.468602</lat>
      <lng>-122.657627</lng>
    </result>
  </results>
</geocoderResults>

#1


1  

Make sure you are outputting the first line in an echo statement or similar:

确保输出echo语句中的第一行或类似内容:

<?php
echo "<?xml version=\"1.0\"?>";
?>
//rest of XML

If you just have <?xml... (outside of PHP tags) as the first line, PHP will think you are trying to use an (undefined) constant xml

如果您只有<?xml ...(在PHP标记之外)作为第一行,PHP会认为您正在尝试使用(未定义的)常量xml

#2


0  

<?php header('Content-type:text/xml;charset=UTF-8'); ?>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<geocoderResults>
  <count>2</count>
  <results>
    <result>
      <description>834 SE LAMBERT CIRCLE</description>
      <lat>45.490943</lat>
      <lng>-122.406561</lng>
    </result>
    <result>
      <description>834 SE LAMBERT ST</description>
      <lat>45.468602</lat>
      <lng>-122.657627</lng>
    </result>
  </results>
</geocoderResults>