如何将 XML 字符串回显到 HTML 页面进行调试?
好的,我有一个 php 脚本,我需要以某种方式查看我的变量之一的值。问题是这个变量是从服务器返回的一个非常长的 XML 字符串。我知道其中有一条错误消息,但我需要实际查看它在说什么。如果我尝试打印或回显该值,它只会显示后面跟着 ... 的部分,或者如果我使用 var_dump 它会执行相同的操作。我什至尝试用该值回显 javascript 警报,但失败了,因为 xml 中存在单引号和双引号,导致警报引号无法正确识别。我只需要查看这个变量的值。有什么建议吗?谢谢。
编辑: 其实说错了。 Echo 和 print 无法正确显示值,因为标签位于 <>括号,因此它被识别为 html 标签。
Okay so I have a php script and I need to somehow view the value of one of my variables. The thing is this variable is a very long string of XML that got returned from a server. I know it has an error message in it but I need to actually see what it is saying. If I try and Print or echo the value it only displays part followed by a ... or if I use var_dump it does the same. I've even gone as far as trying to echo a javascript alert with the value but that fails because there are single and double quotes in the xml causing the alert quotes not to be recognized correctly. I just need to see the value of this variable. Any advice? Thanks.
Edit:
Actually said that wrong. Echo and print don't display the value correctly because the tags are in <> brackets so it is recognizing as an html tag.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 htmlentities 输出 XML 字符串,以便您可以在浏览器中获得它的纯文本视图。
或者,您可以解析 XML 字符串以显示错误消息,但这可能比您需要的更复杂。
You can use htmlentities to output the XML string so that you can get a plaintext view of it in a browser.
Alternatively, you can parse the XML string to reveal the error message, but this may be more complicated than what you need.
尝试
echo htmlentities($var, ENT_COMPAT, 'UTF-8')
Try
echo htmlentities($var, ENT_COMPAT, 'UTF-8')
我总是用这个:
i always use this:
试试这个:
另请参阅:
CDATA -(未解析的)字符数据
Try this:
See also:
CDATA - (Unparsed) Character Data
我通常使用:
因为它只是 <这是一个问题
i usaly use:
as its only the < that are a problem
您只需将 XML 字符串保存到文件中即可。如果它是格式良好的 XML,您可以使用每个浏览器查看它(以及展开/折叠节点 ^^)。
You could just save the XML string to a file. If it's well-formed XML, you can view it with every browser (and expand/collapse nodes ^^).