PHP creates XML with hyphen

Hey everyone,

Please could you assist with the following. I have a PHP that creates dynamic XML with search results from a database. However the XML created contains hyphens/dashes and I cannot parse it because of this. Does anyone know where there problem could be?

[php]<?php
header(“Content-type: text/xml”);
$xmlBody = ‘<?xml version="1.0" encoding="ISO-8859-1"?>’;
$xmlBody .= “”;

$artist =$_POST[‘artist’];
$medium =$_POST[‘medium’];
$size =$_POST[‘size’];
$format =$_POST[‘format’];
$subject =$_POST[‘subject’];
$colour =$_POST[‘colour’];
$price =$_POST[‘price’];
$available =$_POST[‘available’];

$host = “127.0.0.1”;
$user = “root”;
$pass = “”;
$database = “syntegallery”;

$con = mysql_connect($host, $user, $pass) or die (mysql_error());
mysql_select_db($database, $con) or die (“Could not find database”);

$result = mysql_query("SELECT Filename, Thumbnail, Empirical FROM gallery WHERE Artist=’$artist’ AND Medium=’$medium’ AND Category=’$size’ AND Format=’$format’ AND Subject=’$subject’ AND Colour=’$colour’ AND Range=’$price’ AND Available=’$available’ ", $con) or die (“Data not found”);

$i = 0;

while($row = mysql_fetch_array($result))
{
$Filename = $row[“Filename”];
$Thumbnail = $row[“Thumbnail”];
$Empirical = $row[“Empirical”];
$i++;
$xmlBody .= ’

‘.$Filename.’
‘.$Thumbnail.’
‘.$Empirical.’
';
}

$xmlBody .= “”;
print $xmlBody;
mysql_close($con);
exit();
?>[/php]

The created XML looks as follows:

<?xml version="1.0" encoding="ISO-8859-1" ?>

[code]-

  • ABJ004.jpg s_ABJ004.jpg Barry Jackson, "Charging Lion". Bronze, 29 x 53cm. R22,500.00
  • ABJ005.jpg s_ABJ005.jpg Barry Jackson, "Cheetah Group". Bronze, 45 x 60 x 38cm. R47,500.00

[/code]

I can’t see anything that would add dashes. What are you viewing the XML in? It could be the browser or reader that is adding them.

The code looks okay, and since the dashes appear within strings. I think your showing us example code, As the code posted should be fine.

The XML was generated when I removed the variables but the XML structure has remained the same. I viewed this XML in IE/EasyPHP (local web) when opening the PHP file.

Basically I am trying to load the XML into Flash but I am getting an error that the XML is not well formed - I can only assume that this is because of the dashes?

Sponsor our Newsletter | Privacy Policy | Terms of Service