0
<a>
    <b>
        <c key="c1"><![CDATA[d1]]></c>
        <c key="c2"><![CDATA[d2]]></c>
    </b>
</a>

请问用Php获取到 c1 c2 d1 d2

西红柿 254
2019-05-31 提问
1 个回答
1

已采纳
<?php
$xml = <<<xml
<a>
    <b>
        <c key="c1"><![CDATA[d1]]></c>
        <c key="c2"><![CDATA[d2]]></c>
    </b>
</a>
xml;

$xmlString = simplexml_load_string($xml);

$cds = $xmlString->b->c;

foreach ($cds as $key => $value) {
    echo $value->attributes()["key"].PHP_EOL;
    echo $value.PHP_EOL;
}

撰写答案

推广链接