My code seems to work on a Windows 2003 server but on Linux it is producing an extra blank line or two before the xml declaration.
Here is my post.php code:
Code: Select all
<?
$method=$_GET['method']; $id=$_GET['id']; $title=$_GET['title']; $description=$_GET['description'];
require_once("../classes/Post.class.php");
$post = new Post();
$post->$method($id, $title, $description);
?>This calls my Post class get() function to produce the XML.
Here is that code:
Code: Select all
function get()
{
$this->dbConnect();
$query = "SELECT * FROM $this->table ORDER BY id desc";
$result = mysql_db_query (DB_NAME, $query, LINK);
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
$xml .= "<posts>\n";
while($row = mysql_fetch_array($result))
{
$xml .= "<post>\n";
$xml .= "<id>" . $row['id'] . "</id>\n";
$xml .= "<date>" . $row['date'] . "</date>\n";
$xml .= "<title><![CDATA[" . $row['title'] . "]]></title>\n";
$xml .= "<description><![CDATA[" . $row['description'] . "]]></description>\n";
$xml .= "</post>\n";
}
$xml .= "</posts>";
mysql_close();
header("Content-Type: application/xml; charset=UTF-16");
echo $xml;
}When I copy & paste the output XML I get the following:
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1" ?>
<posts>
<post>
<id>11</id>
<date>2006-10-20 03:02:01</date>
<title><![CDATA[Testing #2]]></title>
<description><![CDATA[,mh,mwen.fdwe fe wef ewf ewf wef we]]></description>
</post>
<post>
<id>1</id>
<date>2006-10-19 01:02:03</date>
<title><![CDATA[Testing #1]]></title>
<description><![CDATA[mn kjdbsvsvd vsdvkjdsv dsvovj dvkjodsvkm sdkvoubsdv sv]]></description>
</post>
</posts>I can't reconcile why the very same code would work on one server and not on the next. This has had me chasing my tail for days now. It's only a simple piece of code, but I need to prove the method works before I launch into bulding my project.