【问题标题】:Read values within a XML node读取 XML 节点中的值
【发布时间】:2011-12-24 14:24:16
【问题描述】:

我的 XML 文档包含以下节点:

1 个 macbook air 和 4 个 ipod

我的问题是如何读取“变量”值(1 和 4)并用 php 回显它们。

【问题讨论】:

    标签: php xml


    【解决方案1】:

    您应该使用simplexml XML 解析器和一些正则表达式。

    <?php
    $string = <<<XML
    <?xml version='1.0'?>
    <document>
        <description>1 macbook air and 4 ipods</description>
    </document>
    XML;
    $xml = simplexml_load_string($string);
    $description = $xml->description;
    preg_match('|(\d+) macbook air and (\d+) ipods|', $description, $match);
    
    print_r($match[1] . ' ');
    print_r($match[2]);
    

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-12
      • 1970-01-01
      相关资源
      最近更新 更多