XML和PHP问题? 可以在XML中写PHP,你也可以写C,C++,JAVA,C#......因为XML把它做为数据存起来了呀。问题是,这些只是数据,而不是代码,不可能编译执行的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那请问用PHP输出XML要怎么做啊? 最简单的方法 lookprint <<<END<?xml version="1.0" encoding="GB2312" ?><root text="ROOT" > <menu id="1" text="AAA"> <menu id="12" href="" text="AA"></menu> <menu id="13" href="" text="BB"></menu> <menu id="14" href="" text="CC"></menu> </menu> <menu id="2" text="BBB"> <menu id="21" href="" text="AA"></menu> <menu id="22" href="" text="BB"></menu> <menu id="23" href="" text="CC"></menu> </menu></root>END; 楼上的大大的方法不行的啊...在PHP的环境里只会输出一片空白的. 这个有点奇怪你的需求到底是什么试试这样吧。apache里把.xml文件也作为php文件分析。然后直接加php进去,第一行的<?和?>会有歧义,用echo输出试试行否 打印出来了呀,我刚试的 代码如下,你的要是是空白,那你看一下IE的源代码,可能是<?xml version="1.0" encoding="GB2312" ?>没有在第一行或者<?和xml之间有空格。总之是格式的原因就对了<?php print <<<END<?xml version="1.0" encoding="GB2312" ?><root text="ROOT" ><menu id="1" text="AAA"><menu id="12" href="" text="AA"></menu><menu id="13" href="" text="BB"></menu><menu id="14" href="" text="CC"></menu></menu><menu id="2" text="BBB"><menu id="21" href="" text="AA"></menu><menu id="22" href="" text="BB"></menu><menu id="23" href="" text="CC"></menu></menu></root>END;?>效果如下:<?xml version="1.0" encoding="GB2312" ?> - <root text="ROOT">- <menu id="1" text="AAA"> <menu id="12" href="" text="AA" /> <menu id="13" href="" text="BB" /> <menu id="14" href="" text="CC" /> </menu>- <menu id="2" text="BBB"> <menu id="21" href="" text="AA" /> <menu id="22" href="" text="BB" /> <menu id="23" href="" text="CC" /> </menu> </root> 怎么学好PHP 关于页面等待响应时间长的问题 有用过PDO prepare()方法的朋友吗?关于带in的sql语句如何使用prepare的问题 很急的时间戳问题 - 时间戳转换 如何通过脚本能限制打印网页的URL地址 jpgraph问题 百分求一个PHP函数 [求救]在同一個表中使用UNION,如何才能不出現相同的記錄 正在学XML,但看见书上说IE5都不支持标准的XML1。0是不是啊 关于php glob函数无法遍历带中文路径 关于mysql联合查询的问题!? 关于文字和图片一起上传mysql数据库的问题。
<root text="ROOT" >
<menu id="1" text="AAA">
<menu id="12" href="" text="AA"></menu>
<menu id="13" href="" text="BB"></menu>
<menu id="14" href="" text="CC"></menu>
</menu>
<menu id="2" text="BBB">
<menu id="21" href="" text="AA"></menu>
<menu id="22" href="" text="BB"></menu>
<menu id="23" href="" text="CC"></menu>
</menu>
</root>
END;
apache里把.xml文件也作为php文件分析。
然后直接加php进去,第一行的<?和?>会有歧义,用echo输出试试行否
<?xml version="1.0" encoding="GB2312" ?>没有在第一行或者<?和xml之间有空格。总之是格式的原因就对了
<?php
print <<<END
<?xml version="1.0" encoding="GB2312" ?>
<root text="ROOT" >
<menu id="1" text="AAA">
<menu id="12" href="" text="AA"></menu>
<menu id="13" href="" text="BB"></menu>
<menu id="14" href="" text="CC"></menu>
</menu>
<menu id="2" text="BBB">
<menu id="21" href="" text="AA"></menu>
<menu id="22" href="" text="BB"></menu>
<menu id="23" href="" text="CC"></menu>
</menu>
</root>
END;
?>
效果如下:
<?xml version="1.0" encoding="GB2312" ?>
- <root text="ROOT">
- <menu id="1" text="AAA">
<menu id="12" href="" text="AA" />
<menu id="13" href="" text="BB" />
<menu id="14" href="" text="CC" />
</menu>
- <menu id="2" text="BBB">
<menu id="21" href="" text="AA" />
<menu id="22" href="" text="BB" />
<menu id="23" href="" text="CC" />
</menu>
</root>