Home > Backend Development > PHP Tutorial > 怎么能知道XML对象中有几个一层的元素 simplexml_load_file()

怎么能知道XML对象中有几个一层的元素 simplexml_load_file()

WBOY
Release: 2016-06-23 14:24:55
Original
835 people have browsed it

比如:simplexml_load_file() 后用var_dump()显示如下:
怎么能知道xml中包含几个page ?
下例中page是2个,一个[0],一个[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) "" 							} 		} 	}}
Copy after login


回复讨论(解决方案)

$elem = simplexml_load_string($xml);var_dump($elem->count());
Copy after login
Copy after login
Copy after login

$elem = simplexml_load_string($xml);var_dump($elem->count());
Copy after login
Copy after login
Copy after login


谢谢。这个函数只有php5.3以上才支持,昨天把我的5.2升级到5.5了。不过页面打开后再刷新就很慢-很慢-很慢


$elem = simplexml_load_string($xml);var_dump($elem->count());
Copy after login
Copy after login
Copy after login


谢谢。这个函数只有php5.3以上才支持,昨天把我的5.2升级到5.5了。不过页面打开后再刷新就很慢-很慢-很慢
5.5 有些函数不向下兼容,呵呵,这个需要注意。
不过应该要比以前的版本速度快才对。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template