469,301 Members | 2,272 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,301 developers. It's quick & easy.

Include PHP Code in XML document

228 100+
Hey all,
I am buildin xml based album and i want to include php code into the xml file. The xml file is generated by coffecup and lookks like this:

Expand|Select|Wrap|Line Numbers
  1. <thumbnailer
  2.    x="10"
  3.    y="375"
  4.    w="450"
  5.    h="80"
  6.    myname="thumbs1"
  7.    image1="myalbum/jennifer_aniston_01_s.jpg"
  8.    bigimage1="myalbum/jennifer_aniston_01.jpg"
  9.    imagecaption1="1"
  10.    image2="myalbum/jennifer_aniston_02_s.jpg"
  11.    bigimage2="myalbum/jennifer_aniston_02.jpg"
  12.    imagecaption2="2"
  13.    image3="myalbum/jennifer_aniston_03_s.jpg"
  14.    bigimage3="myalbum/jennifer_aniston_03.jpg"
  15.    imagecaption3="3"
  16.    image4="myalbum/jennifer_aniston_04_s.jpg"
  17.    bigimage4="myalbum/jennifer_aniston_04.jpg"
  18.    imagecaption4="4"
  19.     image5="myalbum/jennifer_aniston_05.jpg"
  20.    bigimage5="myalbum/jennifer_aniston_05.jpg"
  21.    imagecaption5="5"
  22.     image6="myalbum/jennifer_aniston_06.jpg"
  23.    bigimage6="myalbum/jennifer_aniston_06.jpg"
  24.    imagecaption6="6"
  25.   >
  26.   </thumbnailer>
I want to get the images automatically using php. Anyway i can that? Or can i insert XML data into php document?
Dec 13 '08 #1
7 17140
6,050 Expert 4TB
You can read an .XML file by using any of PHP's built in functions.

PHP: XMLReader - Manual

A google for 'php read xml' will do you fine.
Dec 13 '08 #2
8,651 Expert Mod 8TB
two other PHP classes that deal with XML.

PHP: DOMDocument - Manual

PHP: SimpleXML - Manual

Dec 13 '08 #3
You must sent the xml header to the browser in your php file.

Expand|Select|Wrap|Line Numbers
  2. <?php 
  4. header("Content-type:text/xml; charset=utf-8");
  6. echo '<thumbnailer'>;
  9. /* PHP code to generate your data goes here */
  12. echo '</thumbnailer>';
  15. exit;
  16. ?>
Dec 14 '08 #4
228 100+
ur way seems to be easy. but i need to create the file always that means, rgt? My idea is to update only the contents of the <thumbnailer> section of the XML doc (it is a very long,long one). I need to insert the PHP code right in the xml document. Or is it possible to have the php code with XML code in between?
Dec 16 '08 #5
You need to put the xml code into the php file. By sending the xml header to the browser, you tell the browser to render it as an XML document.

To send the XML header to the browser just put this at the top of your php file before any other output :

header("Content-type:text/xml; charset=utf-8");

You CAN'T put php inside XML document BUT you can put xml inside a php document

Hope it clarify!
Dec 16 '08 #6
228 100+
thats very clear, thankx!
Dec 16 '08 #7
6,050 Expert 4TB
Or you could just update the <thumbnailer> section by using one of the many XML classes PHP has - like suggested before.
Dec 16 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Andrew V. Romero | last post: by
21 posts views Thread by Peter Bassett | last post: by
5 posts views Thread by hijwel | last post: by
5 posts views Thread by Tony Strazzeri | last post: by
2 posts views Thread by newsgroups | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.