Home > Software engineering >  how to get more lines from xml feed php
how to get more lines from xml feed php

Time:10-21

Hi i have for exmaple this is feed in xml.

 <SHOPITEM>
<NAME>Snubní prsteny z oceli pro páry</NAME>
<SHORT_DESCRIPTION>
<p>Cena je za 1 prsten</p><p>Snubní prsteny z chirurgické oceli</p>
</SHORT_DESCRIPTION>
<SUPPLIER>Eshop-Sperku</SUPPLIER>
<WARRANTY>24</WARRANTY>
<ITEM_TYPE>product</ITEM_TYPE>
<UNIT>ks</UNIT>
<CATEGORIES>
<CATEGORY>Šperky</CATEGORY>
<CATEGORY>Šperky > Prsteny</CATEGORY>
<CATEGORY>Šperky > Prsteny > Dámské prsteny</CATEGORY>
<CATEGORY>Šperky > Prsteny > Pánské prsteny</CATEGORY>
<CATEGORY>Šperky > Prsteny > Snubní prsteny</CATEGORY>
<CATEGORY>MEGA VÝPRODEJ > 30% sleva</CATEGORY>
</CATEGORIES>

how i get last CATEGORY in categories ?

i use now code like this:

 // Load xml file else check connection
   $xml = simplexml_load_file(feed.xml)
       or die("Error: Cannot create object");
    
   // Assign values
   foreach ($xml->children() as $row) {
       $name = $row->NAME;

Thanks

CodePudding user response:

One way would be

$xml = simplexml_load_file('users.xml')
       or die("Error: Cannot create object");
    
$kids =  $xml->CATEGORIES->children();

echo $kids[count($kids)-1];
  • Related