asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
544 stars 152 forks source link

Get conent from field or SimpleXMLElement convert to array or where tags in xml ? #151

Open shubaivan opened 8 years ago

shubaivan commented 8 years ago

I have SimpleXMLElement and I neeed get content filed (content = 10) I tried

 $xml   = simplexml_load_string($summContent);
 $array = json_decode(json_encode((array) $xml), 1);
 $array = array($xml->getName() => $array);

but have xml - false and 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]

I tried $summContent->content

result = {SimpleXMLElement} [2]
@attributes = {array} [1]
0 = "10"

$xml   = simplexml_load_string($summContent);

exception:

Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found

How do I convert to an array?

UPDATE

I work with Spreadsheet google api and when I crated field for summ I nedd get this summ, after I get by coordinates I have xml with this summ but can not get this field, who knows how to convert this SimpleXMLElement

dump my 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',
  ),
)),
),
))

UPDATE

I get fiel content = 10 like this:

$arraySummContent = (array) $summContent;
$content = $arraySummContent['content'];

But I want know why to :

$xml = simplexml_load_string($summContent);