我正在嘗試生成包含我在應用程序的控制檯中插入的信息的xml文件。它包含標題信息和圖片庫,我有列出圖片庫圖片的問題。一切正常生成,但當我嘗試填充圖像庫的信息它不工作。這是問題的副本,請諮詢,我仍然是初學者,這可能是一個愚蠢的錯誤,但請一個需要幫助。生成XML文件
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 (" & ", " & ", $_xml);
return $_xml;
}
使用DOM或SimpleXml創建XML。這將會照顧你現在面臨的很多問題。此外,ereg家族已被棄用。 – Gordon 2011-05-10 13:43:03
可能的重複[一個簡單的程序到CRUD節點和xml文件的節點值](http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of -xml文件) – Gordon 2011-05-10 13:44:46