foreach xml node return selected element



How can I get only selected value from my xml cdata tag?


So far with help in stackoverflow I can get all the <b> tags in a string



$result = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);

foreach ($result->channel->item as $item) {
$desc = $item->description;
$dom = new DOMDocument($desc);
$dom->loadHTML($desc);
$bold_tags = $dom->getElementsByTagName('b');
foreach($bold_tags as $b) {
echo $b->nodeValue . "<br>";
}


but it will echo out all data which are inside <b>, but I want to get only let's say price. I red in stackoverflow to use ->item(x) to get that value, but nothing is working.If I put it like this echo $b->nodeValue->item(2) . "<br>"; or echo $b->item(2)->nodeValue . "<br>";. So where should I put it or what should I use to get only <b> element with price. The price will always be in the same place.


Here is my CDATA from feed:



<a href="//www.ss.lv/msg/lv/real-estate/flats/riga/purvciems/deblb.html"><img align=right border=0 src="//i.ss.lv/images/2014-10-01/349288/VHkAHkBlRlo=/1.t.jpg" width="160" height="120" alt=""></a>
District: <b><b>Purvciems</b></b><br/>Street: <b><b>Dudajeva g. 12</b></b><br/>Rooms: <b><b>2</b></b><br/>m2: <b><b>50</b></b><br/>Type: <b><b>LT proj.</b></b><br/>: <b><b>3</b> €</b><br/>Price: <b><b>150</b> €/mēn.</b><br/><br/><b><a href="//www.ss.lv/msg/lv/real-estate/flats/riga/purvciems/deblb.html">Apskatīt sludinājumu</a></b><br/><br/>
]]>

No comments:

Post a Comment