Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[PHP] simplexml_load_file und xpath

Empfohlene Antworten

Veröffentlicht

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

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.