XML und PHP Parsen = ERROR

PunkRatte

Well-known member
17 Februar 2007
134
5
Hi,
komme damit irgendwie nicht klar:

es geht darum eine xml-datei von myvideo auszulesen

xml-datei (erreichbar über die url, habe aber die devolver und website id entfernt):
PHP:
  <?xml version="1.0" encoding="UTF-8" ?> 
- <response>
- <myvideo>
  <ttl>1238663706</ttl> 
  <method>myvideo.videos.list_by_user</method> 
  <resultCount>18</resultCount> 
- <movie_list>
- <movie movie_id="5946064">
  <movie_id>5946064</movie_id> 
  <movie_title>Danny und Ich machen Mukke</movie_title> 
  <movie_thumbnail>https://is3.myvideo.de/de/movie16/e3/thumbs/5946064_2.jpg</movie_thumbnail> 
  <movie_length>48</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>1</movie_rating> 
  <movie_views>88</movie_views> 
  <movie_added>1234366472</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/5946064/Danny_und_Ich_machen_Mukke">Danny und Ich machen Mukke</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/5946064/Danny_und_Ich_machen_Mukke"><img class="myvideo_tumbnail" alt="Danny und Ich machen Mukke" title="Danny und Ich machen Mukke" src="https://llnw08.myvideo.de/movie16/e3/thumbs/5946064_2.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/5946064</movie_url> 
  </movie>
+ <movie movie_id="5731180">
  <movie_id>5731180</movie_id> 
  <movie_title>.: Silvester 2008 :.</movie_title> 
  <movie_thumbnail>https://is1.myvideo.de/de/movie3/13/thumbs/5731180_1.jpg</movie_thumbnail> 
  <movie_length>157</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>4</movie_rating> 
  <movie_views>109</movie_views> 
  <movie_added>1230991048</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/5731180/.:_Silvester_2008_:.">.: Silvester 2008 :.</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/5731180/.:_Silvester_2008_:."><img class="myvideo_tumbnail" alt=".: Silvester 2008 :." title=".: Silvester 2008 :." src="https://llnw08.myvideo.de/movie3/13/thumbs/5731180_1.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/5731180</movie_url> 
  </movie>
+ <movie movie_id="5046824">
  <movie_id>5046824</movie_id> 
  <movie_title>Korn vs. Alk</movie_title> 
  <movie_thumbnail>https://is3.myvideo.de/de/movie7/bb/thumbs/5046824_1.jpg</movie_thumbnail> 
  <movie_length>450</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>0</movie_rating> 
  <movie_views>609</movie_views> 
  <movie_added>1220800773</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/5046824/Korn_vs._Alk">Korn vs. Alk</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/5046824/Korn_vs._Alk"><img class="myvideo_tumbnail" alt="Korn vs. Alk" title="Korn vs. Alk" src="https://llnw08.myvideo.de/movie7/bb/thumbs/5046824_1.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/5046824</movie_url> 
  </movie>
+ <movie movie_id="4898764">
  <movie_id>4898764</movie_id> 
  <movie_title>PunkRatte - Standby-Button Tattoo</movie_title> 
  <movie_thumbnail>https://is3.myvideo.de/de/movie13/0a/thumbs/4898764_1.jpg</movie_thumbnail> 
  <movie_length>100</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>0</movie_rating> 
  <movie_views>131</movie_views> 
  <movie_added>1218888099</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/4898764/PunkRatte_-_Standby-Button_Tattoo">PunkRatte - Standby-Button Tattoo</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/4898764/PunkRatte_-_Standby-Button_Tattoo"><img class="myvideo_tumbnail" alt="PunkRatte - Standby-Button Tattoo" title="PunkRatte - Standby-Button Tattoo" src="https://llnw08.myvideo.de/movie13/0a/thumbs/4898764_1.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/4898764</movie_url> 
  </movie>
+ <movie movie_id="4889097">
  <movie_id>4889097</movie_id> 
  <movie_title>Danny vs. Schelln</movie_title> 
  <movie_thumbnail>https://is4.myvideo.de/de/movie13/0d/thumbs/4889097_1.jpg</movie_thumbnail> 
  <movie_length>41</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>5</movie_rating> 
  <movie_views>262</movie_views> 
  <movie_added>1218758416</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/4889097/Danny_vs._Schelln">Danny vs. Schelln</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/4889097/Danny_vs._Schelln"><img class="myvideo_tumbnail" alt="Danny vs. Schelln" title="Danny vs. Schelln" src="https://llnw08.myvideo.de/movie13/0d/thumbs/4889097_1.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/4889097</movie_url> 
  </movie>
+ <movie movie_id="4889020">
  <movie_id>4889020</movie_id> 
  <movie_title>Danny vs. Tacker</movie_title> 
  <movie_thumbnail>https://is1.myvideo.de/de/movie13/fd/thumbs/4889020_3.jpg</movie_thumbnail> 
  <movie_length>103</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>0</movie_rating> 
  <movie_views>97</movie_views> 
  <movie_added>1218756195</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/4889020/Danny_vs._Tacker">Danny vs. Tacker</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/4889020/Danny_vs._Tacker"><img class="myvideo_tumbnail" alt="Danny vs. Tacker" title="Danny vs. Tacker" src="https://llnw08.myvideo.de/movie13/fd/thumbs/4889020_3.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/4889020</movie_url> 
  </movie>
+ <movie movie_id="4438366">
  <movie_id>4438366</movie_id> 
  <movie_title>Tattoo Danny - Peter Enis</movie_title> 
  <movie_thumbnail>https://is4.myvideo.de/de/movie8/77/thumbs/4438366_2.jpg</movie_thumbnail> 
  <movie_length>450</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>0</movie_rating> 
  <movie_views>932</movie_views> 
  <movie_added>1213473863</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/4438366/Tattoo_Danny_-_Peter_Enis">Tattoo Danny - Peter Enis</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/4438366/Tattoo_Danny_-_Peter_Enis"><img class="myvideo_tumbnail" alt="Tattoo Danny - Peter Enis" title="Tattoo Danny - Peter Enis" src="https://llnw08.myvideo.de/movie8/77/thumbs/4438366_2.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/4438366</movie_url> 
  </movie>
+ <movie movie_id="4402517">
  <movie_id>4402517</movie_id> 
  <movie_title>Tattoo Danny - Wellensittich</movie_title> 
  <movie_thumbnail>https://is4.myvideo.de/de/movie9/22/thumbs/4402517_1.jpg</movie_thumbnail> 
  <movie_length>181</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>0</movie_rating> 
  <movie_views>459</movie_views> 
  <movie_added>1213051450</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/4402517/Tattoo_Danny_-_Wellensittich">Tattoo Danny - Wellensittich</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/4402517/Tattoo_Danny_-_Wellensittich"><img class="myvideo_tumbnail" alt="Tattoo Danny - Wellensittich" title="Tattoo Danny - Wellensittich" src="https://llnw08.myvideo.de/movie9/22/thumbs/4402517_1.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/4402517</movie_url> 
  </movie>
+ <movie movie_id="3760989">
  <movie_id>3760989</movie_id> 
  <movie_title>Carson Stormracer Teil 2</movie_title> 
  <movie_thumbnail>https://is5.myvideo.de/de/movie8/1b/thumbs/3760989_2.jpg</movie_thumbnail> 
  <movie_length>30</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>2</movie_rating> 
  <movie_views>331</movie_views> 
  <movie_added>1206381992</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/3760989/Carson_Stormracer_Teil_2">Carson Stormracer Teil 2</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/3760989/Carson_Stormracer_Teil_2"><img class="myvideo_tumbnail" alt="Carson Stormracer Teil 2" title="Carson Stormracer Teil 2" src="https://llnw08.myvideo.de/movie8/1b/thumbs/3760989_2.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/3760989</movie_url> 
  </movie>
+ <movie movie_id="3760786">
  <movie_id>3760786</movie_id> 
  <movie_title>Carson Stormracer Teil1</movie_title> 
  <movie_thumbnail>https://is4.myvideo.de/de/movie8/7c/thumbs/3760786_1.jpg</movie_thumbnail> 
  <movie_length>51</movie_length> 
  <movie_owner_id>2561292</movie_owner_id> 
  <movie_owner>PunkRatte</movie_owner> 
  <movie_owner_url>https://www.myvideo.de/mitglieder/PunkRatte</movie_owner_url> 
  <movie_rating>3</movie_rating> 
  <movie_views>333</movie_views> 
  <movie_added>1206380916</movie_added> 
  <permalink><a href="https://www.myvideo.de/watch/3760786/Carson_Stormracer_Teil1">Carson Stormracer Teil1</a></permalink> 
  <permathumblink><a href="https://www.myvideo.de/watch/3760786/Carson_Stormracer_Teil1"><img class="myvideo_tumbnail" alt="Carson Stormracer Teil1" title="Carson Stormracer Teil1" src="https://llnw08.myvideo.de/movie8/7c/thumbs/3760786_1.jpg"/></a></permathumblink> 
  <movie_url>https://www.myvideo.de/watch/3760786</movie_url> 
  </movie>
  </movie_list>
  </myvideo>
  </response>


myvideos.php (online erreichbar unter https://www.deathboy.de/myvideos.php)
PHP:
	<h1 class="decay">:: Meine Videos</h1>
<br>

<?php
if (file_exists('https://api.myvideo.de/api2_rest.php?method=myvideo.videos.list_by_user&dev_id=XXX&website_id=XXX&per_page=10&page=1&user=2561292'))
  {
  $xml = simplexml_load_file('https://api.myvideo.de/api2_rest.php?method=myvideo.videos.list_by_user&dev_id=XXX&website_id=XXX&per_page=10&page=1&user=2561292');
  var_dump($xml);
  }else
  {
  exit('Error.');
  }
?>

warum erscheint der error???

danke
gruß mike
 
warum erscheint der error???

So komplex ist das Script nun auch nicht. "Error" wird ausgegeben wenn file_exists false liefert. Um rauszufinden warum es das tut schaut man sich die Dokumentation zu file_exists an.

Ich bin mal so nett und zitiere gleich:

Hinweis: Diese Funktion kann nicht mit entfernten Dateien arbeiten, da der Zugriff auf die Datei, die bearbeitet werden soll, über das Dateisystem des Servers möglich sein muss.

Sprich: file_exists ist dafür da, zu prüfen, ob eine Datei lokal auf dem Server existiert. Du rufst file_exists mit einem URL auf, ehrlich gesagt habe ich keine Ahnung was Du damit bezwecken willst. Was auch immer - so geht's jedenfalls nicht.
 
Hinter einer URL muss doch nicht notwendigerweise eine Datei stecken. Ich würde mal grob schätzen, dass das zu 99,999999% eh nicht der Fall is ;)
 
bin kompletter neuling in den gebiet. hab die url so von myvideo bekommen. dahinter soll eine xml datei stecken. wenn ich die url über den internet explorer aufrufe bekomme ich die daten die ich im ersten beitrag gepostet habe.

die soll ich nun mit php parsen... nur wie???

ich tüftel schon seit letzten wochenende damit rum, bekomm irgendwie nichts auf die reihe :-(
 
Ich würds auch nicht direkt ausm Netz laden, sondern erstmal mit curl oder filegetcontents () oä ins System laden und dann parsen.

Habs noch nie versucht direkt ausm Netz zu parsen keine Ahnung ob das so geht.

Ich würd so vorgehen:

Voraussetzung PHP 5 und libcurl aufn Server.

PHP:
$URL = "https://api.myvideo.de/api2_rest.php?method=myvideo.videos.list_by_user&dev_id=XXX&website_id=XXX&per_page=10&page=1&user=2561292";

$curl = curl_init();

curl_setopt ($curl, CURLOPT_URL, $URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($curl);
curl_close($curl);

Mit diesen paar Zeilen hast Du jetzt mittels CURL die XML in der Variable $data drin.

Dann das ganze Parsen:

PHP:
$xml = new SimpleXMLElement($data);

Nun ist das Ganze als Objekt über die Feldnamen ansprechbar.

Zum Beispiel:

PHP:
echo $xml->movie_title;

Sollte den Titel ausgeben. Mit dem Feld bin ich mir nicht ganz sicher ob die Struktur so geliefert wird.

Einfach mal das gelieferte XML genauer anschauen welche Struktur das ist und rumprobieren. Das bekommst Du dann raus wie man die Feldnamen anspricht. Stichwort Objekte und Attribute.

Kannst Dir ja mal die Struktur ausgeben lassen mit:

PHP:
echo "<pre>";
print_r($xml);
echo "</pre>";
 
@Matse1978:

coooooooooooooooool!!! Funktioniert!
hab jetzt erst mal die struktur auslesen lassen - haut hin!!! Seit letzten Wochenende tüftel ich rum damit mir überhaupt was angezeigt wird...
VIELEN DANK!!! - Den Rest bekomm ich hin!

Gruß Mike
 
klappt soweit alles bestens, nur wie mache ich das damit sich beim auslesen alles wiederholt?

wenn ich wie bei den suchergebnissen bei video-seiten ALLE meine videos anzeigen will

soweit bin ich schon, funktionier auch:
PHP:
<table border="1">
 <tr border="1">
  <td border="1"><? echo $xml->myvideo->movie_list->movie->movie_title; ?></td>
 </tr>
 <tr>
  <td border="1"><? echo $xml->myvideo->movie_list->movie->permathumblink; ?></td>
 </tr>
 <tr>
  <td border="1">Länge: <? echo $xml->myvideo->movie_list->movie->movie_length;?></td>
 </tr>
</table>
siehe hier: https://www.deathboy.de/myvideos.php

wie würde das dann aussehen wenn ich die tabellen alle wiederholen will mit einer schleife so das es mir auch noch die restlichen videos mit dazu anzeigt???

gruß mike
 
Im Programmiererforum wird dir kein Code geschrieben. Lies doch bitte mal im Manual, da sind genau solche Beispiele, wie du sie brauchst - afair sogar auch mit Videos und Filmen :pray:
 
Keine Ursache! Sollte es nicht klappen schreib hier einfach nochmal ;)

Am besten lernt man durch selber probieren, aber wenn man garnicht weiterkommt kann ich schonmal Beispiele auf den Code bezogen geben, sofern ichs selber kann :LOL:. Hab einige Jahre nicht mehr programmiert und vor kurzem wieder angefangen. Da vergisst man schon das ein oder andere.

Hab mir das gerade mal genauer überlegt. Ich denke die Daten in ein neues Array über eine foreach Schleife schreiben und anschließend mit einer for Schleife ausgeben sollte gut funzen. Beides mit Zähler.
 
Zuletzt bearbeitet: