如何在PHP中以HTML格式显示XML? [英] How to display XML in HTML in PHP?
本文介绍了如何在PHP中以HTML格式显示XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个XML字符串:
$ string =
< shoes>
< shoe>
< shouename> Shoue< / shouename>
< / shoe>
< / shoes>
;
并且想要像这样在我的网站上显示它:
这是XML字符串内容:
< shoes>
< shoe>
< shouename> Shoue< / shouename>
< / shoe>
< / shoes>
所以我想这样做:
- 不在文本框中 没有外部库,框架等的
- 用适当的新行格式化
- 使用标签格式化
- 不含颜色等,仅限文字
那么如何以简单明了的方式做到这一点?
你的(预格式化的)字符串,你可以将它包装在HTML< pre />
标签中并使用 htmlentities
来转义尖括号: <?PHP echo'< pre>,htmlentities($ string),'< / pre>'; ?>
I have a string with XML:
$string =
"
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
";
And would like display it on my website like this:
This is XML string content:
<shoes>
<shoe>
<shouename>Shoue</shouename>
</shoe>
</shoes>
So I would like to do it:
- on site, not in textbox
- without external libraries, frameworks etc.
- formatted with proper new lines
- formatted with tabs
- without colors etc., only text
So how to do it in plain and simple way?
解决方案
If you just want a plain-text representation of your (pre-formatted) string, you can wrap it in HTML <pre/>
tags and use htmlentities
to escape the angle brackets:
<?PHP echo '<pre>', htmlentities($string), '</pre>'; ?>
这篇关于如何在PHP中以HTML格式显示XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文