我想用PHP 循环遍历出来数据库中图片的值然后把值传给XML中相应的位置应该怎么做啊???
<?xml version="1.0" encoding="euc-kr" ?>
- <URL>
- <Image_Information>
<img_link></img_link>
<big_image>大图地址</big_image>
<thumb_image>小图地址</thumb_image>
</Image_Information>
-</URL>怎么来实现啊?
<?xml version="1.0" encoding="euc-kr" ?>
- <URL>
- <Image_Information>
<img_link></img_link>
<big_image>大图地址</big_image>
<thumb_image>小图地址</thumb_image>
</Image_Information>
-</URL>怎么来实现啊?
$string="<?xml version=\"1.0\" encoding=\"euc-kr\" ?> <URL><Image_Information><img_link></img_link> <big_image>大图地址</big_image> <thumb_image>小图地址</thumb_image> </Image_Information></URL>";
file_put_contents("abc.xml",$string);
$root = $doc->createElement('URL');
$root = $doc->appendChild($root);$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$imgnode = createNode($root, "Image_Information");
createNode($imgnode, "img_link", $row['imglink']);
createNode($imgnode, "big_image", $row['big_image']);
createNode($imgnode, "thumb_image", $row['thumb_image']);
}
$doc->save("./update.xml");function createNode(&$pNode, $nodeName, $nodeValue='', $nodeAttribute = array())
{
global $doc;
$node = $doc->createElement($nodeName);
if($nodeValue != "")
{
$nodeText = $doc->createTextNode($nodeValue);
$node->appendChild($nodeText);
}
if(sizeof($nodeAttribute) > 1)
{
foreach($nodeAttribute as $key=>$value)
{
$node->setAttribute($key, $value);
}
}
$pNode->appendChild($node);
return $node;
}
=>
if(sizeof($nodeAttribute) >= 1)
header('Content-Type:text/xml');
$big = "big_image";//中文需要转码
$thumb = "thumb_image";$dom = new DOMDocument('1.0','euc-kr');
$URL = $dom->createElement('URL');
$dom->appendChild($URL); $Image_Information = $dom->createElement('Image_Information');
$URL->appendChild($Image_Information); $img_link = $dom->createElement('img_link');
$big_image = $dom->createElement('big_image',$big);
$thumb_image = $dom->createElement('thumb_image',$thumb);
$Image_Information->appendChild($img_link);
$Image_Information->appendChild($big_image);
$Image_Information->appendChild($thumb_image);$XMLString = $dom->saveXML();
echo $XMLString;