【问题标题】:How to create XML using PHP [duplicate]如何使用 PHP 创建 XML [重复]
【发布时间】:2013-04-20 04:32:34
【问题描述】:

我是PHP 的初学者。我想动态创建一个XML 文件,我知道该怎么做。但在这种情况下,在XML 文件中,一个节点应该包含一个属性"name",其值来自$_POST 变量。如何编写PHP 代码来创建XML 文件,其中包含具有属性"name" 的节点。

【问题讨论】:

标签: php xml


【解决方案1】:

可能对你有帮助:

<?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扩展名保存文件

【讨论】:

    【解决方案2】:
     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;
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-15
      • 2015-03-23
      • 2012-11-25
      • 2012-12-16
      • 2016-11-14
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多