从谷歌联系人访问totalResults属性返回xml

时间:2017-07-06 17:50:59

标签: php api google-api google-contacts

我试图访问“totalResults”'来自跟随谷歌(联系人)

返回的xml



 <generator version="1.0" uri="http://www.google.com/m8/feeds">Contacts</generator>
 <openSearch:totalResults>29</openSearch:totalResults>
 <openSearch:startIndex>1</openSearch:startIndex>
 <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

how to access attributes in XML上的PHP文档中试用这个PHP教程:

<?php
$string = <<<XML
<a>
 <foo name="one" game="lonely">1</foo>
</a>
XML;

$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"\"\n";
}
?>

以上示例将输出:

name="one"
game="lonely"

选中此SO post以获取更多参考资料。

答案 1 :(得分:0)

$xml = '<generator version="1.0" uri="http://www.google.com/m8/feeds">Contacts</generator>
 <openSearch:totalResults>29</openSearch:totalResults>
 <openSearch:startIndex>1</openSearch:startIndex>
 <openSearch:itemsPerPage>25</openSearch:itemsPerPage>'

$xml = simplexml_load_string($xml);
echo $xml->openSearch->totalResults;