如何将 XML 字符串回显到 HTML 页面进行调试?

发布于 2024-12-15 11:18:55 字数 315 浏览 1 评论 0原文

好的,我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦在深巷 2024-12-22 11:18:56

您可以使用 htmlentities 输出 XML 字符串,以便您可以在浏览器中获得它的纯文本视图。

<?php echo htmlentities( $xml_string); ?>

或者,您可以解析 XML 字符串以显示错误消息,但这可能比您需要的更复杂。

You can use htmlentities to output the XML string so that you can get a plaintext view of it in a browser.

<?php echo htmlentities( $xml_string); ?>

Alternatively, you can parse the XML string to reveal the error message, but this may be more complicated than what you need.

天生の放荡 2024-12-22 11:18:56

尝试echo htmlentities($var, ENT_COMPAT, 'UTF-8')

Try echo htmlentities($var, ENT_COMPAT, 'UTF-8')

肥爪爪 2024-12-22 11:18:56

我总是用这个:

echo "<pre>". htmlentities($s) . "</pre>";

i always use this:

echo "<pre>". htmlentities($s) . "</pre>";
人生百味 2024-12-22 11:18:56

试试这个:

echo '<pre>'.$xml_string.'</pre>';

另请参阅:
CDATA -(未解析的)字符数据

Try this:

echo '<pre>'.$xml_string.'</pre>';

See also:
CDATA - (Unparsed) Character Data

提笔落墨 2024-12-22 11:18:56

我通常使用:

echo nl2br(str_replace('<', '<', $xml));

因为它只是 <这是一个问题

i usaly use:

echo nl2br(str_replace('<', '<', $xml));

as its only the < that are a problem

以为你会在 2024-12-22 11:18:56

您只需将 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 ^^).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文