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());