How can I know that the XML object has several layers of elements: simplexml_load_file ()

Source: Internet
Author: User
How can we know that the XML object contains several layers of elements simplexml_load_file () such as simplexml_load_file () & nbsp; and then var_dump () is shown as follows: how many pages & nbsp; are contained in xml ;? In the following example, there are two pages, one [0] and one [how can we know that there are several layers of elements in the XML object: simplexml_load_file ()
For example, simplexml_load_file () is displayed as follows with var_dump:
How many pages are contained in xml?
In the following example, there are two pages, one [0] and the other [1].




object(SimpleXMLElement)#24 (1) 

["page"]=> array(2) 

[0]=> object(SimpleXMLElement)#25 (2) 

["@attributes"]=> array(1) 

["id"]=> string(1) "0" 

["background"]=> object(SimpleXMLElement)#38 (1) 

["@attributes"]=> array(1) 

["color"]=> string(11) "255,255,255" 



[1]=> object(SimpleXMLElement)#26 (1) 

["@attributes"]=> array(1) 

["preview"]=> string(100) "" 



}
}

Share:
------ Solution --------------------
$elem = simplexml_load_string($xml);
var_dump($elem->count());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.