我有SimpleXMLElement,我需要获取内容(内容= 10)我试过
$xml = simplexml_load_string($summContent);
$array = json_decode(json_encode((array) $xml), 1);
$array = array($xml->getName() => $array);
但是有xml - false和array - false
$summContent = {SimpleXMLElement} [6]
id = "https://spreadsheets.google.com/feeds/cells/1-fR7MXmjsr0juPWsbpK9RSY_WVW_XK77-krsmEcmdc4/oxi7ruj/private/full/R14C2"
updated = "2016-07-26T10:49:49.902Z"
category = {SimpleXMLElement} [1]
title = "B14"
content = "10"
link = {array} [2]
我尝试了$summContent->content
result = {SimpleXMLElement} [2]
@attributes = {array} [1]
0 = "10"
$xml = simplexml_load_string($summContent);
异常:
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found
如何转换为数组?
更新
我使用Spreadsheet google api,当我为summ创建字段时,我得到了这个summ,在我得到坐标后我得到了这个summ的xml但是无法得到这个字段,谁知道如何转换这个SimpleXMLElement
转储我的SimpleXMLElement:
$summContent
SimpleXMLElement::__set_state(array(
'id' => 'https://spreadsheets.google.com/feeds/cells/1-fR7MXmjsr0juPWsbpK9RSY_WVW_XK77-krsmEcmdc4/ood4aof/private/full/R14C2',
'updated' => '2016-07-26T11:30:46.528Z',
'category' =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'scheme' => 'http://schemas.google.com/spreadsheets/2006',
'term' => 'http://schemas.google.com/spreadsheets/2006#cell',
),
)),
'title' => 'B14',
'content' => '10',
'link' =>
array (
0 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'rel' => 'self',
'type' => 'application/atom+xml',
'href' => 'https://spreadsheets.google.com/feeds/cells/1-fR7MXmjsr0juPWsbpK9RSY_WVW_XK77-krsmEcmdc4/ood4aof/private/full/R14C2',
),
)),
1 =>
SimpleXMLElement::__set_state(array(
'@attributes' =>
array (
'rel' => 'edit',
'type' => 'application/atom+xml',
'href' => 'https://spreadsheets.google.com/feeds/cells/1-fR7MXmjsr0juPWsbpK9RSY_WVW_XK77-krsmEcmdc4/ood4aof/private/full/R14C2/lj40r',
),
)),
),
))
更新
我这样得到fiel content = 10:
$arraySummContent = (array) $summContent;
$content = $arraySummContent['content'];
但我想知道为什么:
$xml = simplexml_load_string($summContent);