0

i am trying to generate xml files that contain the information that i have inserted in the console of the application. it contain title information and a image gallery, i am having problem with listing the image gallery pictures. everything else is generated correctly but when i try to populate the information of the image gallery it dont work. this is a copy of the problem, please advice and i am still a beginner and this might be a stupid mistake but please a need help.

function array2XML($anews)
    {   

        $images = $this->selectAllImages($anews);


        $_xml = "       <tag path=\"".wk_show($anews['FileLink'])."\">\n"
               ."           <title>".wk_show($anews['Title'])."</title>\n"
               ."           <dateT>".wk_show($anews['Date'])."</dateT>\n"
               ."           <desc>".wk_show($anews['Content'])."</desc>\n"
               ."           <photos pathTh=\"admin/images/news/thumbs/\" pathPr=\"admin/images/news/preview/\">\n";

// here is the problem when i remove it it works but it only take 1 image of the gallery
                foreach($images as $image)
                    {   
                    echo "i am in the loop <br />";

                        $_xml ="           <tag path=\"".wk_show($image['FileLink'])."\"/>\n";
                    }
               $_xml ="           </photos>\n" 
               ."       </tag>\n";

        $_xml = preg_replace(array("/\&([a-z\d\#]+)\;/i", "/\&/", "/\#\|\|([a-z\d\#]+)\|\|\#/i", "/(\=\"\-\/\%\?\!\'\(\)\[\\{\}\ \#\+\,\@_])/e"),
                             array("#||\\1||#", "&", "&\\1;", "'&#'.ord('\\1').';'"),
                             $_xml);

        $_xml = ereg_replace (" & ", " &amp; ", $_xml);

        return $_xml;
    }
wandos
  • 1,581
  • 2
  • 20
  • 39
  • Use DOM or SimpleXml to create the XML. That will take care of a lot of problems you are facing right now. Also, the ereg family is deprecated. – Gordon May 10 '11 at 13:43
  • possible duplicate of [A simple program to CRUD node and node values of xml file](http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of-xml-file) – Gordon May 10 '11 at 13:44

3 Answers3

1

Inside the loop you're reassigning $xml, not concatenating it. Use $xml .= as opposed to $xml =

Mel
  • 6,077
  • 1
  • 15
  • 12
0

Why don't you use SimpleXML to generate the XML output? To generate a valid XML output out of a PHP array you can check out PHP official documentation on this: http://php.net/manual/en/book.simplexml.php Just check the first couple of examples which will help you generate a valid xml and also convert an xml string into an associative array.

0

You are using simpleXML, Please follow the link hope it ll b solve your problem

http://php.net/manual/en/book.simplexml.php

PHP official document help u to check out put array format.

saint
  • 3,787
  • 5
  • 19
  • 17