php simplexml - 在 cdata 上提取大量数字

发布于 2024-09-19 12:23:08 字数 615 浏览 5 评论 0原文

我的 xml 有以下部分:

<book number="AB 123" type="SCI">
  <info>
    <type code="FIC"><![CDATA[Fiction]]></status>
    <publish-time><![CDATA[20090110214000]]></publish-time>
  </info>
</book>

如果我这样做:

echo $key->info->type;

我会得到很好且简单的“小说”,

但如果我这样做:

echo $key->info->publish-time;

我会得到“0”。

我认为这可能与这个(20090110214000)是一个数字有关,但我尝试了各种方法来提取它,但没有成功。当我 print_r 时,我看到 20090110214000 就在那里,但为什么我不能得到该值(作为数字或字符串)进行回显或将其分配给变量?

I have the following part of my xml:

<book number="AB 123" type="SCI">
  <info>
    <type code="FIC"><![CDATA[Fiction]]></status>
    <publish-time><![CDATA[20090110214000]]></publish-time>
  </info>
</book>

If I do:

echo $key->info->type;

I get nice and easy "Fiction"

BUT if I do:

echo $key->info->publish-time;

I get "0".

I thought it might have to do with this (20090110214000) being a number, but I tried various ways to extract that but with no success. When I print_r I see the 20090110214000 just fine in there but why can I not get that value (as a number or string) to be echoed or assign it to a variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

本王不退位尔等都是臣 2024-09-26 12:23:08

您所做的是 $key->info->publish - time,基本上是未定义值减去未知常量(结果为 0)。

使用 $key->info->{'publish-time'} 检索正确的值。

What you do is $key->info->publish - time, basically a substraction of an undefined value minus an unknown constant (results in 0).

Use $key->info->{'publish-time'} to retrieve the correct value.

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