Morty222 Posted October 10, 2008 Share Posted October 10, 2008 I want to convert data from mysql to an xml file using php. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/127864-php-mysql-to-xml/ Share on other sites More sharing options...
Maq Posted October 10, 2008 Share Posted October 10, 2008 Turn SQL into XML with PHP Quote Link to comment https://forums.phpfreaks.com/topic/127864-php-mysql-to-xml/#findComment-661990 Share on other sites More sharing options...
Morty222 Posted October 10, 2008 Author Share Posted October 10, 2008 I am getting the data back to xml, just getting this error: Whitespace is not allowed at this location. <name>A & E Mailers</name> ------------^ Dont know how to get the white space out. Any suggestions? Code below: <?php header("Content-type: text/xml"); include('mysql.php'); $query = "select * from tbl_customers ORDER BY name asc"; $resultID = mysql_query($query); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<customers>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<entry>\n"; // Escaping illegal characters $row['name'] = str_replace("&", "&", $row['name']); $row['name'] = str_replace("<", "<", $row['name']); $row['name'] = str_replace(">", ">", $row['name']); $row['name'] = str_replace("\"", """, $row['name']); $xml_output .= "\t\t<name>" . $row['name'] . "</name>\n"; $xml_output .= "\t</entry>\n"; } $xml_output .= "</customers>"; echo $xml_output; ?> Quote Link to comment https://forums.phpfreaks.com/topic/127864-php-mysql-to-xml/#findComment-662021 Share on other sites More sharing options...
Maq Posted October 10, 2008 Share Posted October 10, 2008 Maybe you need to escape the space, add this: $row['name'] = str_replace(" ", " ", $row['name']); Quote Link to comment https://forums.phpfreaks.com/topic/127864-php-mysql-to-xml/#findComment-662084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.