Problem with output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cobus
Forum Newbie
Posts: 1
Joined: Fri Sep 26, 2003 6:50 pm

Problem with output

Post 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
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post 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.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post 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
Post Reply