tyrisia Posted April 3, 2008 Share Posted April 3, 2008 Hi all, I'm writing a php script to output xml to a flash movie. The script contains a function siteloklink that outputs an encoded link from the included sitelokpw.php script. The output contains many & characters which i think is stopping my xml from parsing correctly. <? header("Content-Type: text/xml"); require"slpw/sitelokpw.php"; /* include"slpw/sitelokpw.php"; ----- Application: Flash-dB GuestBook Version 2.0 Details: mySQL and PHP powered GuestBook Author: Mohsin Sumar Website: http://www.flash-db.com Support: http://www.flash-db.com/Board Notes: Coments are marked by using comment entries symbols. Eg: // Comment ----- */ // Part One - Initiate a mySQL Database Connection // Database Connectivity Variables and other Variables $DBhost = "localhost"; // Database Server $DBuser = ""; // Database User $DBpass = ""; // Database Pass $DBName = "tyrisia"; // Database Name $table = "userlink"; //$user = $slusername; $user = 'admin'; // Database Table $i = 0; $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error()); mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); $sql = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date"; $alltracks = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); $numalltracks = mysql_num_rows($alltracks); print('<?xml version="1.0" encoding="UTF-8" ?>' . "\n"); print '<download>'; if($numalltracks == 0) { print 'No tracks purchased yet'; } else { for ($i=0; $i<$numalltracks; $i++) { $trackname = mysql_result($alltracks, $i, 'title'); $ahref = mysql_result($alltracks, $i, 'link'); $date = mysql_result($alltracks, $i, 'date'); print '<downloadinfo trackname = "' . $trackname . '" link = "' . siteloklink($ahref,1) . '"/>'; }print '</download>'; ?> Can anyone suggest a way round the problem? xml error is "A semi colon character was expected" thanks in advance:) Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/ Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 There are probably illegal characters in the trackname and link. I would use SimpleXML to generate the XML. It will do all the conversion for you. http://us2.php.net/manual/en/ref.simplexml.php Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508617 Share on other sites More sharing options...
stopblackholes Posted April 3, 2008 Share Posted April 3, 2008 you should redo your xml so it looks something like this instead of using attributes. you can parse anything by putting it in CDATA. Otherwise you will need to strip and remove all the illegal characters in php before it hits the parser. <?PHP $query = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date"; $xmlresult = mysql_query($query, $DBConn) or die("Data not found."); $xml_output .= "<download>" for($x = 0 ; $x < mysql_num_rows($xmlresult) ; $x++){ $items = mysql_fetch_assoc($xmlresult); $xml_output .= "<item>" $xml_output .= "<title><![CDATA[" .$title."]]></title>" $xml_output .= "<content><![CDATA[" .$content."]]></content>" $xml_output .= " </item>" } $xml_output .= "</download>" echo $xml_output; ?> EDIT yeah what rhodesa posted. Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508637 Share on other sites More sharing options...
tyrisia Posted April 3, 2008 Author Share Posted April 3, 2008 does all this require php5? coz i need a solution that works with php4, and I'm having no luck implementing the advice:( Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508682 Share on other sites More sharing options...
stopblackholes Posted April 3, 2008 Share Posted April 3, 2008 yeah it will work for php4 you will need to change the way you parse it in flash though. example xml parser for flash myXML = new XML() myXML.ignoreWhite = true ///change to your php xml file myXML.load("yourxml.php") myXML.onLoad = function(success){ if(success){ var root = this.firstChild nodes = root.childNodes // output each item for(var i=0; i<nodes.length; i++) { subnodes = nodes[i].childNodes var trackname = subnodes[0].firstChild.toString() var ahref = subnodes[1].firstChild.toString() var date = subnodes[2].firstChild.toString() ///you can put it into a array or dynamically attach a movie clip here } //end loop //you can assign your array to a dataprovider here or whatexver } else trace("Error loading XML document") } Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508698 Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 Try this...i updated the print line and also found you were missing a brace: <?php header("Content-Type: text/xml"); require"slpw/sitelokpw.php"; /* include"slpw/sitelokpw.php"; ----- Application: Flash-dB GuestBook Version 2.0 Details: mySQL and PHP powered GuestBook Author: Mohsin Sumar Website: http://www.flash-db.com Support: http://www.flash-db.com/Board Notes: Coments are marked by using comment entries symbols. Eg: // Comment ----- */ // Part One - Initiate a mySQL Database Connection // Database Connectivity Variables and other Variables $DBhost = "localhost"; // Database Server $DBuser = ""; // Database User $DBpass = ""; // Database Pass $DBName = "tyrisia"; // Database Name $table = "userlink"; //$user = $slusername; $user = 'admin'; // Database Table $i = 0; $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error()); mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); $sql = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date"; $alltracks = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error()); $numalltracks = mysql_num_rows($alltracks); print('<?xml version="1.0" encoding="UTF-8" ?>' . "\n"); print '<download>'; if($numalltracks == 0) { print 'No tracks purchased yet'; } else { for ($i=0; $i<$numalltracks; $i++) { $trackname = mysql_result($alltracks, $i, 'title'); $ahref = mysql_result($alltracks, $i, 'link'); $date = mysql_result($alltracks, $i, 'date'); print '<downloadinfo trackname = "' . htmlspecialchars($trackname) . '" link = "' . htmlspecialchars(siteloklink($ahref,1)) . '"/>'; } } print '</download>'; ?> Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508699 Share on other sites More sharing options...
tyrisia Posted April 3, 2008 Author Share Posted April 3, 2008 nope, that didn't work either. I think it's to do with running siteloklink function whilst parsing maybe? Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508713 Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 You can open this file as a URL right? If you do, do you see the XML? If you see the XML does the browser say there are any errors in the XML? Link to comment https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/#findComment-508736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.