php 正则重复截取字符串

我获取的数据是这样的
这是xml数据

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header/>
    <soapenv:Body>
        <p237:getNewSampleSerialNumsOutput xmlns:p237="http://www.cat.com/sos/2008/07/15/EquipmentService/">
            <Equipment>
                <p463:serialNumber xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15">ZBD11674</p463:serialNumber>
                <p463:make xsi:nil="true" xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15"/>
            </Equipment>
            <Equipment>
                <p463:serialNumber xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15">ZBF11179</p463:serialNumber>
                <p463:make xsi:nil="true" xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15"/>
            </Equipment>
            <Equipment>
                <p463:serialNumber xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15">ZBF11507</p463:serialNumber>
                <p463:make xsi:nil="true" xmlns:p463="http://www.cat.com/dds/Equipment/2008/07/15"/>
            </Equipment>
        </p237:getNewSampleSerialNumsOutput>
    </soapenv:Body>
</soapenv:Envelope>

然后我想要根据标签Equipment把他们截取成一个数组(内容和标签一起获取)【实在不行不拿标签也行,我自己加上去】

然后代码是这样

preg_match_all('/<Equipment>.*<\/Equipment>/',$res,$a);

但是获取的却是截取第一个<Equipment>到最后一个</Equipment>,中间的区域都不去识别

https://img1.mukewang.com/5c8f38600001e14608000060.jpg

请问有什么优化的方法吗

Qyouu
浏览 544回答 3
3回答

梦里花落0921

<Equipment>[\s\S]+?<\/Equipment> 点击查看

ITMISS

str.match(/[^><]+(?=<\/Equipment>)/img; php不太了解这是js 正则匹配标签中的内容
打开App,查看更多内容
随时随地看视频慕课网APP