My php5 code below works fine and generates correct output like this.. http://www.xbrlplanet.org/planet/xbrlprojects2xml.php
Except when I insert the ":" into the "g:markers" echo command below.
Can somebody volunteer the correct syntax so I get <g:markers> <g:markers/> below?
Thanks very much
Code: Select all
<?php include ('../admin/config.php');
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=mysql_connect ("$dbhost", "$dbuser", "$dbpass");
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($dbname, $connection);
if (!$db_selected) {
die ('Can\'t use db database : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM Projects WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<!--prepared for demo purposes only. -->';
echo '<!--distributed at http://www.xbrlplanet.org -->';
echo '<g:markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'country="' . $row['country'] . '" ';
echo 'url="' . $row['url'] . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'cat="' . $row['cat'] . '" ';
echo '/>';
}
// End XML file
echo '</g:markers>';
?>