如何通过 php 通过 xml xpath 查找 nil 元素
我有一些元素为零。返回的元素位于时间戳中,我想使用 getdate() 将所有 nil 元素转换为当前日期。如果我没有使用正确的术语或提出正确的问题,我很抱歉,如果您理解,请随意编辑。
这是 XML:
<tickets type="array" count="2">
<ticket>
<solved-at type="datetime">2012-02-20T17:58:34-05:00</solved-at>
</ticket>
<ticket>
<solved-at type="datetime" nil="true"/>
</ticket>
</tickets>
php:
$xml = new SimpleXMLElement($result);
$solved_at = $xml->xpath('ticket/solved-at');
... array
echo "Ticket time solved at:" . $solved_at[$i]. "<br/>";
返回:
Ticket time solved at:2012-02-20T17:58:34-5:00<br/>
Ticket time solved at:
我想返回 UNIX 中 xml 中空金额的当前日期时间,有什么想法吗?我尝试了以下方法,但没有成功,得到与上面相同的结果:
if (is_null($solved_at[$i])) {
$solved_at = getdate(); }
I have some elements that are nil. The returned elements are in a timestamp and I want to turn all the nil elements to a current date using getdate()
. I'm sorry if im not using the right terminology or asking the right questions, feel free to edit if you understand.
Here is XML:
<tickets type="array" count="2">
<ticket>
<solved-at type="datetime">2012-02-20T17:58:34-05:00</solved-at>
</ticket>
<ticket>
<solved-at type="datetime" nil="true"/>
</ticket>
</tickets>
The php:
$xml = new SimpleXMLElement($result);
$solved_at = $xml->xpath('ticket/solved-at');
... array
echo "Ticket time solved at:" . $solved_at[$i]. "<br/>";
The returned:
Ticket time solved at:2012-02-20T17:58:34-5:00<br/>
Ticket time solved at:
I'd like to return the current datetime in UNIX for the null amounts in the xml, any ideas? I have tried the below but to no avail, I get same results as above:
if (is_null($solved_at[$i])) {
$solved_at = getdate(); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。
Try this.