want to create XML file using PHP

naveensingh

Senior Member
Joined
Feb 15, 2010
Messages
915
Reaction score
297
Hi,
is there any way to create a xml file using PHP , i have tired by DOM but not able to make that. is there any sample code.

thanks
 
Try googling with keyword "PHP XML" there are plenty of samples.
 
Code:
<?php

header("Content-Type: application/xml; charset=utf-8"); 

echo <<<EOS
<?xml version="1.0" encoding="UTF-8"?>
<doc>
  <!-- data here -->
</doc>
EOS;

?>

There you go.
 
Code:
<?php
$filename = "newxmlfile";
$filetype = ".xml";
$filepath = "files/";
$file = $filepath.$filename.$filetype;
$input = "type your xml here";

$filehandle = fopen($file, 'w') or die("Failed to open" .$file. ".");
fwrite($filehandle, $input) or die("Failed to write to " .$file. ".");
fclose($filehandle);
echo "Success. " .$file. " was created.";
?>
the variables are as follows:

$filename = your desired file name (not the extention)
$filepath = the directory where you want it saved to (relative to your php doc)
$filetype = the type of file (in this case .xml)
$file = ignore this
$input = put your xml in here (you will need to add a xml header though)

If this was any help then please press thanks :)
 
there are thousand of way to create xml file man fopen , print , etc whats ur exact need ?
 
Back
Top