Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

14.6 XML mit SimpleXML parsen

Problem

Sie möchten ein XML-Dokument auf sehr einfache Art und Weise verarbeiten, von dem Sie die Struktur bereits kennen, wie zum Beispiel ein RSS-Dokument.

Lösung

Verwenden Sie die neue SimpleXML-Erweiterung in PHP 5.

$feed = 'http://pear.php.net/rss.php';
$rss  = simplexml_load_file($feed);

if ($rss === false) {
    die("Konnte RSS-Feed nicht laden.");
}
foreach ($rss->item as $item) {

    printf('<p><a href="%s">%s</a><br />%s</p>',
            $item->link, htmlspecialchars($item->title),
            htmlspecialchars($item->description));
}

Diskussion

Die SimpleXML-Erweiterung bietet eine vollkommen neue API für XML-Dokumente, die in PHP 5 zum allerersten Mal implementiert wurde. Ziel dieser Extension ist es, Benutzern Zugriff auf XML-Dokumente zu ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book