dqiatvbi61502 2014-03-21 22:35 采纳率: 0%
浏览 31
已采纳

PHP解析XML数据

I have something like this:

  <client type="s" name="root" desc="" protocol="server" protocolext="" au="0" thid="0x15e9190">
     <request="0000" srvid="0000" time="" history="" answered=""></request>
     <times login="2013-04-16T10:59:16+0200" online="7001" idle="0"></times>
     <connection ip="127.0.0.1" port="0">OK</connection>
  </client>

Now, i need to parse this data into a PHP variables, something like this:

 $client_type = s; $name = root; $conn_ip = 127.0.0.1;

...and so on,is there a way to do that?

Tried bash, but it would be much easier if it can be done with php

  • 写回答

4条回答 默认 最新

  • donglugou6652 2014-03-21 22:43
    关注

    PHP has XML support. I like to use SimpleXML.

    $xml = new SimpleXMLElement($xmlString);
    
    $client_type = (string)$xml['type'];
    $name = (string)$xml['name'];
    
    $conn_ip = (string)$xml->connection['ip'];
    

    Easy.

    DEMO: https://eval.in/124545

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

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法