URLLoader - loading XML created with PHP

in my flex app, i am gathering data to display from an XML file


private function loadXml():void { 
 var loader:URLLoader = new URLLoader(); 
 loader.addEventListener(Event.COMPLETE, onXmlLoaded); 
 loader.load(new URLRequest("thefile.xml")); 
}

this works just fine…but when I want the XML file to be generated through PHP (so changing the above file to thefile.php, it doesn’t work anymore.

and the issue is not in my PHP code as it properly outputs in XML format.

im guessing URLRequest & URLLoader arent meant for dynamic XML files?
any thoughts?

thanks!

are you encoding the xml to UTF8 in your php?

well, here is my php code:


<?php
header("Content-type: text/xml; charset: utf-8");

function db_connect()
{
   $result = mysql_connect('localhost', 'user', 'pass');
   mysql_select_db('database',$result);
   if (!$result)
     print "Could not connect to database server";
   else
     return $result;
}

$conn = db_connect();

echo "<items>";

$items = mysql_query("SELECT a, b FROM test");
while($row = mysql_fetch_array($items)){
	echo "<subitem>";
	echo "<detailA>".$row['a']."</detailA>";
	echo "<detailB>".$row['b']."</detailB>";
	echo "</subitem>";
}

echo "</items>";

?>

but if i load my XML directly (hardcoded), outputting the exact same data that the PHP file would, everything works fine

ps - i also tried adding an extra echo line in my php just in case:


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

I’m not a php coder but I know there is a way to enconde your string in utf8.

Flash only understands utf8, so it’s possible that when you save your xml to a local file you encode it in utf8.

Putting that xml tag only informs of the codification, this doesn’t change the actual encoding of the file.

This is what you need: http://es2.php.net/manual/en/function.utf8-encode.php

BTW You’ll need to put all your xml text into a string before encoding, and do the echo after the encoding.