将多个表单值存储到xml文件中

时间:2011-02-03 05:31:21

标签: php xml

我正在尝试使用php将多个表单值存储到xml文件中但是在这里我只能存储一次发布的值。如果我下次发布它会更新。如何保留它们

我在变量中获取值。

$xmlBeg = "<?xml version='1.0' encoding='ISO-8859-1'?>";
     $rootELementStart = "<$u>"; 
     $rootElementEnd = "</$u>"; 
     $xml_document= $xmlBeg; 
     $xml_document .= $rootELementStart;
      $xml_document .= "<box>"; 
        $xml_document .= $con; --//it is getting value of posted
        $xml_document .= "</box>"; 

1 个答案:

答案 0 :(得分:0)

如果您正在使用XML,则最好使用PHP's XML extensions之一。

以下是与DOM相关的代码:

$dom  = new DOMDocument('1.0', 'iso-8859-1'); // utf-8 would be better though
$root = $dom->createElement($u);              // create root element
$box  = $dom->createElement('box', $con);     // create box element with content
$root->appendChild($box);                     // make box a child of root
$dom->appendChild($root);                     // make root the document root
echo $dom->save('filename.xml');              // save

这会将XML保存在名为 filename.xml 的文件中 您可以使用$dom->load('filename.xml')从文件加载XML。

另见

相关问题