oneside Geschrieben 15. Mai 2009 Geschrieben 15. Mai 2009 Hallo, ich versuche gerade eine Twitter XML-Datei per PHP einzulesen, scheitere aber an der Angabe für xpath. Ich nutze folgende Funktion: function get_rss_items($url) { // retrieve search results if($xml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA)) { $result["title"] = $xml->xpath("/feed/entry/title"); foreach($result as $key => $attribute) { $i=0; foreach($attribute as $element) { $ret[$i][$key] = (string)$element; $i++; } } return $ret; } else return false; } [/PHP] Wenn ich die Funktion jetzt für folgenden URL ausführe: Code: [code] http://search.twitter.com/search.atom?q=from:ashtonfans&rpp=5[/code] Funktioniert es nicht, ich bekomme einfach nichts zurück. Ich habe es schon mit unterschiedlichen xpath-Angaben versucht, bekomme es aber nicht hin. Es liegt wohl an der Formatierung der XML Datei nehme ich an. Wenn ich mir das Ergebnis von simplexml_load_file mal durch var_dump($xml) ansehe, bekomme ich dieses Ergebnis: [PHP]object(SimpleXMLElement)#1 (5) { ["id"]=> string(50) "tag:search.twitter.com,2005:search/from:ashtonfans" ["link"]=> array(4) { [0]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "text/html" ["rel"]=> string(9) "alternate" ["href"]=> string(52) "http://search.twitter.com/search?q=from%3Aashtonfans" } } [1]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(3) { ["type"]=> string(20) "application/atom+xml" ["rel"]=> string(4) "self" ["href"]=> string(61) "http://search.twitter.com/search.atom?q=from:ashtonfans&rpp=5" } } [2]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(3) { ["type"]=> string(37) "application/opensearchdescription+xml" ["rel"]=> string(6) "search" ["href"]=> string(40) "http://search.twitter.com/opensearch.xml" } } [3]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(3) { ["type"]=> string(20) "application/atom+xml" ["rel"]=> string(7) "refresh" ["href"]=> string(83) "http://search.twitter.com/search.atom?q=from%3Aashtonfans&rpp=5&since_id=1807292034" } } } ["title"]=> string(32) "from:ashtonfans - Twitter Search" ["updated"]=> string(20) "2009-05-05T18:36:45Z" ["entry"]=> array(4) { [0]=> object(SimpleXMLElement)#5 (7) { ["id"]=> string(38) "tag:search.twitter.com,2005:1708640515" ["published"]=> string(20) "2009-05-05T18:36:45Z" ["link"]=> array(2) { [0]=> object(SimpleXMLElement)#10 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "text/html" ["rel"]=> string(9) "alternate" ["href"]=> string(49) "http://twitter.com/ashtonfans/statuses/1708640515" } } [1]=> object(SimpleXMLElement)#11 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "image/png" ["rel"]=> string(5) "image" ["href"]=> string(95) "http://s3.amazonaws.com/twitter_production/profile_images/192332891/Picture_4_bigger_normal.png" } } } ["title"]=> string(118) "â€Å“I want to be like Tom Cruise from The Outsiders and go on and do amazing movies for a long time.â€Â ~Ashton Kutcher" ["content"]=> string(118) "â€Å“I want to be like Tom Cruise from The Outsiders and go on and do amazing movies for a long time.â€Â ~Ashton Kutcher" ["updated"]=> string(20) "2009-05-05T18:36:45Z" ["author"]=> object(SimpleXMLElement)#12 (2) { ["name"]=> string(27) "ashtonfans (ashton kutcher)" ["uri"]=> string(29) "http://twitter.com/ashtonfans" } } [1]=> object(SimpleXMLElement)#4 (7) { ["id"]=> string(38) "tag:search.twitter.com,2005:1708445493" ["published"]=> string(20) "2009-05-05T18:14:45Z" ["link"]=> array(2) { [0]=> object(SimpleXMLElement)#13 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "text/html" ["rel"]=> string(9) "alternate" ["href"]=> string(49) "http://twitter.com/ashtonfans/statuses/1708445493" } } [1]=> object(SimpleXMLElement)#14 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "image/png" ["rel"]=> string(5) "image" ["href"]=> string(95) "http://s3.amazonaws.com/twitter_production/profile_images/192332891/Picture_4_bigger_normal.png" } } } ["title"]=> string(104) "â€Å“I think good things come to those who want something so bad they can't sit still.â€Â ~ Ashton Kutcher" ["content"]=> string(104) "â€Å“I think good things come to those who want something so bad they can't sit still.â€Â ~ Ashton Kutcher" ["updated"]=> string(20) "2009-05-05T18:14:45Z" ["author"]=> object(SimpleXMLElement)#15 (2) { ["name"]=> string(27) "ashtonfans (ashton kutcher)" ["uri"]=> string(29) "http://twitter.com/ashtonfans" } } [2]=> object(SimpleXMLElement)#3 (7) { ["id"]=> string(38) "tag:search.twitter.com,2005:1680748716" ["published"]=> string(20) "2009-05-02T19:24:21Z" ["link"]=> array(2) { [0]=> object(SimpleXMLElement)#16 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "text/html" ["rel"]=> string(9) "alternate" ["href"]=> string(49) "http://twitter.com/ashtonfans/statuses/1680748716" } } [1]=> object(SimpleXMLElement)#17 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "image/png" ["rel"]=> string(5) "image" ["href"]=> string(95) "http://s3.amazonaws.com/twitter_production/profile_images/192332891/Picture_4_bigger_normal.png" } } } ["title"]=> string(132) ""Men think highly of those who rise rapidly in the world; whereas nothing rises quicker than dust, straw, and feathers." _Lord Byron" ["content"]=> string(142) ""Men think highly of those who rise rapidly in the world; whereas nothing rises quicker than dust, straw, and feathers." _Lord Byron" ["updated"]=> string(20) "2009-05-02T19:24:21Z" ["author"]=> object(SimpleXMLElement)#18 (2) { ["name"]=> string(27) "ashtonfans (ashton kutcher)" ["uri"]=> string(29) "http://twitter.com/ashtonfans" } } [3]=> object(SimpleXMLElement)#2 (7) { ["id"]=> string(38) "tag:search.twitter.com,2005:1677523969" ["published"]=> string(20) "2009-05-02T09:32:21Z" ["link"]=> array(2) { [0]=> object(SimpleXMLElement)#19 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "text/html" ["rel"]=> string(9) "alternate" ["href"]=> string(49) "http://twitter.com/ashtonfans/statuses/1677523969" } } [1]=> object(SimpleXMLElement)#20 (1) { ["@attributes"]=> array(3) { ["type"]=> string(9) "image/png" ["rel"]=> string(5) "image" ["href"]=> string(95) "http://s3.amazonaws.com/twitter_production/profile_images/192332891/Picture_4_bigger_normal.png" } } } ["title"]=> string(99) "â€Å“Small minds discuss people. Average minds discuss events. Great minds discuss ideas.â€Â -unknown" ["content"]=> string(99) "â€Å“Small minds discuss people. Average minds discuss events. Great minds discuss ideas.â€Â -unknown" ["updated"]=> string(20) "2009-05-02T09:32:21Z" ["author"]=> object(SimpleXMLElement)#21 (2) { ["name"]=> string(27) "ashtonfans (ashton kutcher)" ["uri"]=> string(29) "http://twitter.com/ashtonfans" } } } } Hat jemand eine Idee? Danke Gruß Oneside Beitrag bearbeiten/löschen Zitieren
_n4p_ Geschrieben 16. Mai 2009 Geschrieben 16. Mai 2009 1) var_dump($result) dürfte etwa so aussehen: Array ( [0] => SimpleXMLElement Object ( [0] => <titel> ) ) 2) list( , $result["title"]) = $xml->xpath("/feed/entry/title"); Zitieren
Empfohlene Beiträge
Dein Kommentar
Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.