Jump to content

Adding Images to XML and displaying with PHP


wispas

Recommended Posts

After hours I finally managed to get this Simple XML working now. I now want to enchance and was wondering if anyone knows how to add image links to the XML and display it with PHP.

 

XML File

 

<?xml version="1.0" encoding="utf-8"?>

  <library>

  <shelf id="fiction">

    <book>

    <title>Of Mice and Men</title>

    <author>John Steinbeck</author>

<desc>Whats this</desc>

    </book>

    <book>

    <title>Harry Potter and the Philosopher's Stone</title>

    <author>J.K. Rowling</author>

<desc>Whats that</desc>

    </book>

  </shelf>

  </library>

 

PHP File

 

<?php

  $library = simplexml_load_file('library.xml');

  foreach ($library->shelf as $shelf) {

      printf("Shelf %s\n", $shelf['id']);

      foreach ($shelf->book as $book) {

          printf("Title: %s\n", $book->title);

          printf("Author: %s\n", $book->author);

  printf("Description: %s\n", $book->desc);

      }

  }

  ?>

 

I want to add a image field to the XML for each of the books and display it with PHP.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.