>  기사  >  백엔드 개발  >  php 怎么把表单数据写入到XML文件中

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

WBOY
WBOY원래의
2016-06-13 13:49:44818검색

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으로 문의하세요.