• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Wiedermal Probleme mit XML und PHP

maria1

Mitglied
Hallo,

Bekomme es einfach nicht hin diese xml auszulesen..
http://www.imdbapi.com/?t=saw&r=xml&plot=full

Code:
Code:
  $xml = simplexml_load_file("http://www.imdbapi.com/?t=saw&r=xml&plot=full");
  $xml->movie[0]->title[0];
  echo $xml->movie[0]->title[0];

Was mache ich falsch ?

Auslesen will ich so ziemlich alles und in ne Tabelle schreiben.

Danke
 
So habs geschafft das ich die XML mal auslese.

Code:
Code:
$xml = simplexml_load_file("http://www.imdbapi.com/?t=saw&r=xml&plot=full");
$xml->movie[0];
print "<pre>";
print_r($xml); 
print "</pre>";

Ausgabe:

http://poll.1x.de/imdb/index2.php

Wie bekomm ich nun nicht das ganze array sondern alle teile der arrays einzeln und in einer tabelle ?

So funktionierts nicht

Code:
print $xml->title[0];

Jetzt sollte meiner Meinung nach der titel ausgegeben werden... und so solls dann weitergehen

print $xml->title[0]->year[0]... usw.
 
simplexml_load_file() erzeugt ein Objekt, welches wiederum als Array die Datensätze enthält. Siehe Manual:
PHP: simplexml_load_file - Manual

Du musst nur per foreach() durch dieses Ergebnis gehen, dann kannst Du jeden einzelnen Datensatz auslesen und damit machen was Du willst.
 
http://poll.1x.de/imdb/index2.php


K
appier das mit dem durchhangeln nicht...

habs schon so versucht

$xml->movie->title;
$xml->response->movie->title;
$xml->title;

Nichts klappt

Code:
Code:
  $xml = simplexml_load_file("http://www.imdbapi.com/?t=saw&r=xml&plot=full");/*Zeile 9 in meiner PHP Datei */ 
    print_r($xml);
echo $xml->title;

das shema ist etwas anders wie bei den tutorial xml's

<movie title="" year="" >

in den tut's aber

<movie>
<title></title>
<year></year>
</movie>
 
Hi,

auf die Attribute in den einzelnen Elementen kannst du wie folgt zugreifen:

Code:
<?php$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
<moviedb>
    <movie title="Film1" year="2010" >
        <bla>blub</bla>
    </movie>
    <movie title="Film2" year="2011" >
        <bla>blub</bla>
    </movie>
</moviedb>';
$xml = simplexml_load_string($xml);
if (count($xml->movie) > 0) {
    foreach ($xml->movie as $node) {
        echo $node['title'];
    echo $node['year'];
    }
}
?>

bzw

Code:
[B]​[/B]<?php$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
<moviedb>
    <movie title="Film1" year="2010" >
        <bla>blub</bla>
    </movie>
    <movie title="Film2" year="2011" >
        <bla>blub</bla>
    </movie>
</moviedb>';


$xml = simplexml_load_string($xml);
    
echo $xml->movie[0]['title'];
echo $xml->movie[0]['year'];


echo $xml->movie[1]['title'];
echo $xml->movie[1]['year'];



?>

Viele Grüße
 
Gut danke funktioniert .

Ich habe das zweite Beispiel genutzt.

Nun will ich dieses auch für eine andere XML verwenden nähmlich bei dieser

Code:
PHP:
$movies = simplexml_load_file("http://api.themoviedb.org/2.1/Movie.getInfo/de/xml/e21e9c696d044bc397e5376310e7d1ab/187");
echo $movies->movie[0]['popularity'];


Leider klappt es aber nicht , sollte aber gleich wie bei der anderen funnktionieren oder ?

Danke
 
Die hat einen anderen Aufbau und du fragst auch kein Attribut ab.

PHP:
$movies->movies[0]->movie[0]->popularity[0]
 
Danke, ich denke XML werd ich nie verstehen :/

zb. will ich nun das Poster auslesen , nicht alle nur das 2te..

http://api.themoviedb.org/2.1/Movie.getInfo/de/xml/e21e9c696d044bc397e5376310e7d1ab/671

Code:
[COLOR=#000000][FONT=monospace]<images>
[/FONT][/COLOR][COLOR=#000000][FONT=monospace]<image[/FONT][/COLOR][COLOR=#000000][FONT=monospace] type="poster"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] url="http://cf2.imgobject.com/t/p/w92/uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] size="thumb"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] width="92"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] height="138"[/FONT][/COLOR][COLOR=#000000][FONT=monospace]id="4ea5d65f9dc3d83c3b0009eb"[/FONT][/COLOR][COLOR=#000000][FONT=monospace]/>[/FONT][/COLOR][COLOR=#000000][FONT=monospace][/FONT][/COLOR]
[COLOR=#000000][FONT=monospace]<image[/FONT][/COLOR][COLOR=#000000][FONT=monospace] type="poster"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] url="http://cf2.imgobject.com/t/p/w154/uLGaJ9FgPWf7EUgwjp9RTmHemw8.jpg"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] size="w154"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] width="154"[/FONT][/COLOR][COLOR=#000000][FONT=monospace] height="231"[/FONT][/COLOR][COLOR=#000000][FONT=monospace]id="4ea5d65f9dc3d83c3b0009eb"[/FONT][/COLOR][COLOR=#000000][FONT=monospace]/>[/FONT][/COLOR]

Whttp://api.themoviedb.org/2.1/Movie.getInfo/de/xml/e21e9c696d044bc397e5376310e7d1ab/671enn das noch funktioniert hab ichs endlich xD
 
Ich habs jetzt nicht getestet, aber ich denke so sollte es gehen...

Code:
$movies->movies[0]->movie[0]->images[0]->image[1]['url']
 
Zurück
Oben