Question

I need to output what is outputted from the foreach loop that I am using, without the extraneous array tags surrounding it. An example of some output that I have is...

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [type] => text
        )

    [0] => SMEs spend £6.89bn on unused technology
)

The code I am using to output the above is below

$xml = simplexml_load_file('http://news.telecomsworldplc.co.uk/atom.xml');
echo "<pre>";
foreach($xml->entry as $entry){
    foreach($entry->title as $title){
        print_r($title);
    }
}
echo "</pre>";

The output needs to be just "SMEs spend £6.89bn on unused technology"... Would it be implode I use?

Thanks!

Was it helpful?

Solution

Try below code, It's working here

$xml = simplexml_load_file('http://news.telecomsworldplc.co.uk/atom.xml');
echo "<pre>";
foreach($xml->entry as $entry){ 
    foreach($entry->title as $key=>$title){
        print_r($key." => ".$title. "<br/>");
    }
}
echo "</pre>";
exit;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top