Page 1 of 1

Converting php to xml

Posted: Fri Jun 01, 2007 12:54 pm
by maestro
Hi everyone ,

i have been trying to convert this code to an xml by using headers but this error keeps occuring

Warning: Cannot modify header information - headers already sent by (output started at /home/other/db2student/labdb224/public_html/xml1.php:1) in /home/other/db2student/labdb224/public_html/xml1.php on line 1

This is the code in php :

Code: Select all

<?php header('Content-Type: text/xml');?>
<?php echo "<?xml version='1.0'?>"?>

<?php echo "<?xml-stylesheet type='text/xsl' href='xsl/projections.xsl'?>"?>

<projections>
<?php

$dbhost = "******";
$dbname = "*****";
$dbuser = "*****";
$dbpass = "*****";


mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$query="SELECT * FROM projections";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {
$movie=mysql_result($result,$i,"movie");
$room_number=mysql_result($result,$i,"room_number");
$start_time=mysql_result($result,$i,"start_time");
$end_time=mysql_result($result,$i,"end_time");
$date=mysql_result($result,$i,"date");
$projectionid=mysql_result($result,$i,"projectionid");


?>
	<projection>
		<titlos> <?php echo $movie; ?> </titlos>
		<room_number> <?php echo $room_number; ?> </room_number>
		<start_time> <?php echo $start_time; ?> </start_time>
		<end_time> <?php echo $end_time; ?> </end_time>
		<date> <?php echo  $date; ?> </date>
	</projection>
<?

$i++;
}

?>
</projections>
I would apreciate it if someone could help me ,
thanks in advance :)

Re: Converting php to xml

Posted: Fri Jun 01, 2007 1:18 pm
by superdezign
... Is there any whitespace before you attempt to change the header information?

Posted: Fri Jun 01, 2007 1:23 pm
by maestro
nope :/

Posted: Fri Jun 01, 2007 1:32 pm
by feyd
There's something there. Whether you may see it or not, there is. I would bet it's a BOM (byte-order marker.)

Posted: Fri Jun 01, 2007 1:36 pm
by maestro
Well this is the code the exact way its executed :

http://www.mediafire.com/?3txymfnczfg

Posted: Fri Jun 01, 2007 1:47 pm
by superdezign
Yeah, there's extra.. something at the start of your file, but you can't touch it through a regular editor.

What I did was copied all of the text up to the first character, deleted that file, and created a new one, then pasted the code.

Try Visual Studio, Dreamweaver, or Notepad++ for the best results.

Posted: Fri Jun 01, 2007 1:48 pm
by John Cartwright
From my experience, most users get a hidden character as a result of using Dreamweaver :wink:

Posted: Fri Jun 01, 2007 1:49 pm
by superdezign
Jcart wrote:From my experience, most users get hidden character as a result of using Dreamweaver :wink:
Yeah, Dreamweaver has multiple ways of creating files that give different results. If you do it by right-clicking in the file browser, and creating new file, you should be fine.

Posted: Fri Jun 01, 2007 1:50 pm
by maestro
Thnx for help everyone , saved the file in ANSI through notepad and it works :D

Posted: Fri Jun 01, 2007 1:52 pm
by maestro
The only problem i have now is that an error occurs when trying to parse data with "&".

Posted: Fri Jun 01, 2007 1:55 pm
by superdezign
Umm... Not sure why. Try to str_replace & with &.

Posted: Fri Jun 01, 2007 2:25 pm
by pedrotuga
maestro wrote:The only problem i have now is that an error occurs when trying to parse data with "&".
post the error report please

Posted: Fri Jun 01, 2007 2:59 pm
by volka
http://en.wikipedia.org/wiki/Xml wrote:An entity reference is a placeholder that represents that entity. It consists of the entity's name preceded by an ampersand ("&") and followed by a semicolon (";"). XML has five predeclared entities:

* & (&, ampersand)
* < (<, less than)
* > (>, greater than)
* &apos; (', apostrophe)
* " (", quotation mark)
Replace all those characters by their entity representation in normal data nodes.

Posted: Fri Jun 01, 2007 3:04 pm
by maestro
Thanks for the help everyone :wink: