我是PHP
的初学者。我想动态创建一个XML
文件,我知道如何做到这一点。但在这种情况下,在XML
文件中,一个节点应包含属性“name”,其值为$_POST
变量。如何编写PHP
代码来创建包含属性“name”的节点的XML
文件。
答案 0 :(得分:0)
它可能对您有所帮助:
<?php
// Send the headers
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo '<xml>';
// echo some dynamically generated content here
echo '</xml>';
?>
最后使用.php
扩展名
答案 1 :(得分:0)
As a solution to your problem please try executing following example code snippet
The below code snippet is created on basis of assumption that there is a form for user registration containing fields such as email ,address depicting the procedure for dynamically generation of **xml** content using php
<?php
$xmlstring='<xml>';
if($_SERVER['REQUEST_METHOD']=='POST')
{
$xmlstring.='<user>
<email>'.$POST['email'].'</email>
<address>'.$_POST['address'].'</address>
</user>';
}
$xmlstring.='</xml>';
header('Content-type:text/xml');
echo $xmlstring;
die;
?>