undefinedfix
Sign in

Ask PHP to get XML value

qwiou edited in Sat, 27 Aug 2022
<a>
    <b>
        <c key="c1"><![CDATA[d1]]></c>
        <c key="c2"><![CDATA[d2]]></c>
    </b>
</a>

Can I get C1 C2 D1 D2 with PHP

1 Replies
ePumps
commented on Sat, 27 Aug 2022
<?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;
}
lock This question has been locked and the reply function has been disabled.