XML和PHP问题?

mojojojo 2005-11-24 02:31:10
<?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>

以上是一个.XML文件.我想把上面的AAA和BBB用PHP的变量替换,然后输出一棵树.
可以在XML文件里可以写PHP吗?如果可以怎么写啊.如果不可以要用什么方法来实现啊??


谢谢各位大大~!


...全文
216 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
assassin5616 2005-11-25
  • 打赏
  • 举报
回复
打印出来了呀,我刚试的 代码如下,你的要是是空白,那你看一下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>
helloyou0 2005-11-25
  • 打赏
  • 举报
回复
也不行。应该是头的问题。
helloyou0 2005-11-25
  • 打赏
  • 举报
回复
这个。。。有点奇怪。。。你的需求到底是什么

试试这样吧。
apache里把.xml文件也作为php文件分析。
然后直接加php进去,第一行的<?和?>会有歧义,用echo输出

试试行否
mojojojo 2005-11-24
  • 打赏
  • 举报
回复
楼上的大大的方法不行的啊...在PHP的环境里只会输出一片空白的.
assassin5616 2005-11-24
  • 打赏
  • 举报
回复
最简单的方法 look

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;


mojojojo 2005-11-24
  • 打赏
  • 举报
回复
那请问用PHP输出XML要怎么做啊?
moodboy1982 2005-11-24
  • 打赏
  • 举报
回复
可以在XML中写PHP,你也可以写C,C++,JAVA,C#......
因为XML把它做为数据存起来了呀。问题是,这些只是数据,而不是代码,不可能编译执行的。

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧