0
我很初學PHP
。我想動態創建一個XML
文件,我知道如何做到這一點。但在這種情況下,在XML
文件中,一個節點應包含屬性「名稱」,其值爲$_POST
變量。如何編寫用於創建XML
文件的PHP
代碼,該文件包含具有屬性「名稱」的節點。如何使用PHP創建XML
我很初學PHP
。我想動態創建一個XML
文件,我知道如何做到這一點。但在這種情況下,在XML
文件中,一個節點應包含屬性「名稱」,其值爲$_POST
變量。如何編寫用於創建XML
文件的PHP
代碼,該文件包含具有屬性「名稱」的節點。如何使用PHP創建XML
它可能對你會有所幫助:
<?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
擴展
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;
?>
重複:http://stackoverflow.com/questions/2038535/php-create-new -xml-file-and-write-data-to-it,http://stackoverflow.com/questions/3212982/need-to-write-xml-using-php-how – elclanrs 2013-04-26 04:53:33
夥計, 我從這裏得到了答案鏈接。這就是我需要的。 http://php.net/manual/en/domdocument.createattribute.php 謝謝。 – user2322331 2013-04-26 04:58:55