Include PHP Code in XML document

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samvb
    New Member
    • Oct 2006
    • 228

    Include PHP Code in XML document

    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:

    Code:
    <thumbnailer
       x="10"
       y="375"
       w="450"
       h="80"
       myname="thumbs1"
       image1="myalbum/jennifer_aniston_01_s.jpg"
       bigimage1="myalbum/jennifer_aniston_01.jpg"
       imagecaption1="1"
       image2="myalbum/jennifer_aniston_02_s.jpg"
       bigimage2="myalbum/jennifer_aniston_02.jpg"
       imagecaption2="2"
       image3="myalbum/jennifer_aniston_03_s.jpg"
       bigimage3="myalbum/jennifer_aniston_03.jpg"
       imagecaption3="3"
       image4="myalbum/jennifer_aniston_04_s.jpg"
       bigimage4="myalbum/jennifer_aniston_04.jpg"
       imagecaption4="4"
        image5="myalbum/jennifer_aniston_05.jpg"
       bigimage5="myalbum/jennifer_aniston_05.jpg"
       imagecaption5="5"
        image6="myalbum/jennifer_aniston_06.jpg"
       bigimage6="myalbum/jennifer_aniston_06.jpg"
       imagecaption6="6"
      >
      </thumbnailer>
    I want to get the images automatically using php. Anyway i can that? Or can i insert XML data into php document?
    Last edited by Markus; Dec 13 '08, 06:32 PM. Reason: added # tags.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      two other PHP classes that deal with XML.

      PHP: DOMDocument - Manual

      PHP: SimpleXML - Manual

      regards

      Comment

      • dumm
        New Member
        • Dec 2008
        • 10

        #4
        You must sent the xml header to the browser in your php file.

        Code:
        <?php 
        
        header("Content-type:text/xml; charset=utf-8");
        
        echo '<thumbnailer'>;
        
        
        /* PHP code to generate your data goes here */
        
        
        echo '</thumbnailer>';
        
        
        exit;
        ?>

        Comment

        • samvb
          New Member
          • Oct 2006
          • 228

          #5
          RE: clarify a bit please

          Originally posted by dumm
          You must sent the xml header to the browser in your php file.

          Code:
          <?php 
          
          header("Content-type:text/xml; charset=utf-8");
          
          echo '<thumbnailer'>;
          
          
          /* PHP code to generate your data goes here */
          
          
          echo '</thumbnailer>';
          
          
          exit;
          ?>
          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?

          Comment

          • dumm
            New Member
            • Dec 2008
            • 10

            #6
            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!

            Comment

            • samvb
              New Member
              • Oct 2006
              • 228

              #7
              thats very clear, thankx!

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Or you could just update the <thumbnailer> section by using one of the many XML classes PHP has - like suggested before.

                Comment

                Working...