Page 1 of 1

Problem with output

Posted: Fri Sep 26, 2003 6:50 pm
by cobus
I am trying to write xml content to a newly create file call test.xml.
The following is part of the script i use.

Code: Select all

<?php
header('Content-Type: text/xml');
header("Content-Disposition: filename=$filename");

echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";

//echo more xml

$filename = 'test.xml';
fopen($filename,'x+');

//$thefile is the xml string
fwrite($filename,$thefile);
fclose($filename);

?>
However, everytime i run this script, a file (text.xml) is created but it is empty! the XML is then output to the browser. Can anyone please indicate to me how best to tackle this bug of mine! Thanks

Posted: Fri Sep 26, 2003 9:00 pm
by Stoneguard
Shouldn't you be assigning your XML string to the variable you are writing to the file?

Code: Select all

<?php

$thefile ='<?xml version="1.0" encoding="UTF-8"?>' . "\n"; 
 
?>
Currently you are just writing an unset variable out.

Posted: Fri Sep 26, 2003 9:34 pm
by Cruzado_Mainfrm
yes, like Stoneguard said you are just writing nothing to the page, be sure to set $thefile to something xml-compliant this time, rather than null :D