首页  >  文章  >  后端开发  >  php 怎么把表单数据写入到XML文件中

php 怎么把表单数据写入到XML文件中

WBOY
WBOY原创
2016-06-13 13:49:44816浏览

php 如何把表单数据写入到XML文件中?
php 如何把表单数据写入到XML文件中?

求教了,最好给段代码看看!

------解决方案--------------------

PHP code
require('config.php');
$doc = new DOMDocument('1.0', "gb2312");
$root = $doc->createElement('URL');
$root = $doc->appendChild($root);
$sql = "select * from cdb_forums";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
  $imgnode = createNode($root, "Image_Information");
  createNode($imgnode, "img_link", $row['fid']);
  createNode($imgnode, "big_image", $row['type']);
  createNode($imgnode, "thumb_image", $row['status']);
}
$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;
} <div class="clear">
                 
              
              
        
            </div>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn