dongyi4420 2014-03-20 13:51
浏览 76
已采纳

使用PHP从XML文档中的属性中提取信息

I was unable to find an answer to my question after browsing some promising titles so I figured I would try my luck!

I'm attempting to extract information from XML files generated from a back-end we use at work. The information is not formatted like a normal XML document, so it's been a little difficult to extract what I need. I'm hoping that I can eventually put this information in a table, but I'll be happy if I can at least extract the values.

An example string is as follows:

<Event Name="Last Reef" VenueName="Theater" EventDate="2014-03-21 15:00:00" DirectLink="https://tickets.ctsciencecenter.org/Public/loader.asp?target=hall.asp?event=45259"/>

And I'm trying to get:

Event Name:
Venue Name:
Event Date:
Direct Link:

I'm assuming I need to use substr, but I've never dealt with a string like this.

If you take a moment to look at this, I would greatly appreciate it!

  • 写回答

4条回答 默认 最新

  • dongyin2885 2014-03-20 14:04
    关注

    simplexml_load_string() makes working with XML easy for basic tasks like this:

    <?php
    $event= simplexml_load_string('<Event Name="Last Reef" VenueName="Theater" EventDate="2014-03-21 15:00:00" DirectLink="https://tickets.ctsciencecenter.org/Public/loader.asp?target=hall.asp?event=45259"/>');
    ?>
    
    Event Name: <?= $event['Name']; ?><br>
    Venue Name: <?= $event['VenueName']; ?><br>
    Event Date: <?= $event['EventDate']; ?><br>
    Direct Link: <?= $event['DirectLink']; ?>
    

    See it in action

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料