# Adding Images to XML and displaying with PHP

**URL:** <https://forum.kirupa.com/t/adding-images-to-xml-and-displaying-with-php/258081>\
**Category:** programming\
**Created:** [April 20, 2008, 6:34pm UTC](https://forum.kirupa.com/t/adding-images-to-xml-and-displaying-with-php/258081 "2008-04-20T18:34:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wispas](https://avatars.discourse-cdn.com/v4/letter/w/9de0a6/32.png) [@wispas](https://forum.kirupa.com/u/wispas)\
**Post date:** [April 20, 2008, 6:34pm UTC](https://forum.kirupa.com/t/adding-images-to-xml-and-displaying-with-php/258081/1 "2008-04-20T18:34:42Z")

</div>

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  
> ", $shelf[‘id’]);  
> foreach ($shelf-\>book as $book) {  
> printf("Title: %s  
> ", $book-\>title);  
> printf("Author: %s  
> ", $book-\>author);  
> printf("Description: %s  
> ", $book-\>desc);  
> }  
> }  
> ?\>

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