Echo SimpleXMLElement object

I have an array that looks like this.

Array
(
    [@attributes] => Array
        (
            [version] => 2.0
        )

    [channel] => SimpleXMLElement Object
        (
            [title] => Active Fire Incident Page
            [link] => http://www.ci.austin.tx.us/fact/default.cfm
            [description] => This page provides information on active Austin/Travis County Fire incidents.  Data is updated every 3 minutes.

            [lastBuildDate] => Wed, 23 Nov 2016 10:59:38 PM GMT
            [copyright] => 2016 City of Austin. All rights reserved.
            [language] => en-us
            [item] => SimpleXMLElement Object
                (
                    [title] => E ST ELMO RD/SHERATON AVE
                    [link] => http://www.ci.austin.tx.us/fact/default.cfm
                    [description] => AFD - 4700 S Congress Ave - BOX -Structure Fire - Wed, 23 Nov 2016 10:51 PM 
                    [pubdate] => Wed, 23 Nov 2016 10:51 PM 
                )

        )

)

How can I repeat the last part of an array? This section:

                    [title] => E ST ELMO RD/SHERATON AVE
                    [link] => http://www.ci.austin.tx.us/fact/default.cfm
                    [description] => AFD - 4700 S Congress Ave - BOX -Structure Fire - Wed, 23 Nov 2016 10:51 PM 
                    [pubdate] => Wed, 23 Nov 2016 10:51 PM 

With this code:

echo $xml->channel->item->link;

I get

Notice:Trying to get property of non-object
+4
source share
2 answers
echo ($xml['channel'])->item->link;  

This is the solution.

0
source

You are using the wrong code, try

foreach($xml->channel->item as $key => $product){
   echo $product->link;

OR directly

 echo $xml->channel->item->link;
+2
source

Source: https://habr.com/ru/post/1661784/


All Articles