Shamsul Kamal
asked on
How to get second layer output from XML and convert to php variable ?
Hi,
I have the following scripts :
But i received the following error :
Warning: Illegal string offset 'items' in /home/internet/public_html /test/test string4.ph p on line 42
Warning: Illegal string offset 'item' in /home/internet/public_html /test/test string4.ph p on line 42
Warning: Invalid argument supplied for foreach() in /home/internet/public_html /test/test string4.ph p on line 42
May i know how to get the variable inside the "items" and "item" ?
I have tried "foreach ($xml['items']['item'] as $key => $value)" but it produce the above error.
Hope anybody can help me by providing the correct script.
I have the following scripts :
<?
$xml="<whmcsapi>
<action>getinvoice</action>
<result>success</result>
<invoiceid>242347</invoiceid>
<invoicenum></invoicenum>
<userid>25209</userid>
<date>2017-12-21</date>
<duedate>2018-01-11</duedate>
<datepaid>0000-00-00 00:00:00</datepaid>
<lastcaptureattempt>0000-00-00 00:00:00</lastcaptureattempt>
<subtotal>50.00</subtotal>
<credit>0.00</credit>
<tax>3.00</tax>
<tax2>0.00</tax2>
<total>53.00</total>
<balance>53.00</balance>
<taxrate>6.00</taxrate>
<taxrate2>0.00</taxrate2>
<status>Unpaid</status>
<paymentmethod>banktransfer</paymentmethod>
<notes></notes>
<ccgateway></ccgateway>
<items>
<item>
<id>304494</id>
<type>Domain</type>
<relid>52025</relid>
<description>Domain Renewal - xxx.com - 1 Year/s (11/01/2018 - 10/01/2019)</description>
<amount>50.00</amount>
<taxed>1</taxed>
</item>
</items>
<transactions></transactions>
</whmcsapi>";
$content .= '<table border="1" cellpadding="5" style="border-collapse: collapse;border: 1px solid #cacaca">';
$content .= '<tr><th colspan="2" bgcolor="thistle">ITEMS '.print_r($xml).'</th></tr>';
foreach ($xml['items']['item'] as $key => $value) {
$content .= '<tr><td><b>Description</b></td><td>'.$value['description'].'</td></tr>';
$content .= '<tr><td><b>Amount</b></td><td>'.$value['amount'].'</td></tr>';
}
$content .= '</table>';
return $content;
?>
But i received the following error :
Warning: Illegal string offset 'items' in /home/internet/public_html
Warning: Illegal string offset 'item' in /home/internet/public_html
Warning: Invalid argument supplied for foreach() in /home/internet/public_html
May i know how to get the variable inside the "items" and "item" ?
I have tried "foreach ($xml['items']['item'] as $key => $value)" but it produce the above error.
Hope anybody can help me by providing the correct script.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER