开发者

Generating XML files

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 t开发者_如何学Goake 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;
    }


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜