I have a document that it's structure is like below.
There are a lot of <entry>
. My question is how can I output the <uri>
of each entry? And another question, how can I output only the USERNAME
?
This is the file I want to get the usernames http://search.twitter.com/search.atom?q=yankees
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:google="http://base.google.com/ns/1.0" xml:lang="en-US" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.w3.org/2005/Atom" xmlns:twitter="http://api.twitter.com/" xmlns:georss="http://www.georss.org/georss">
<entry>
<author>
<name></name>
<uri>http://twitter.com/USERNAME</uri>
</author>
</entry>
You should use SimpleXML some kind of a loop which goes trough all the s. (
foreach($xml->entry as $entry)
loop should work fine, I think.)And for the second: if it is always
http://twitter.com/USERNAME
, simply count the prefix's length than use a substr.Resources to use: substr, SimpleXML, SimpleXML
You can use Xpath queries http://www.php.net/manual/en/simplexmlelement.xpath.php or http://php.net/manual/en/domxpath.query.php