0

I'm trying to access 'totalResults' from following xml which was returned by google(contacts)

 <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>

2 Answers 2

1

Try this PHP tutorial from the PHP docs on how to access attributes in XML:

<?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"; } ?> 

The above example will output:

name="one" game="lonely" 

Check this SO post for additional reference.

Sign up to request clarification or add additional context in comments.

Comments

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; 

1 Comment

Sorry , it didn't work. If you want to see the full original xml file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.