PHP to XML
<?php
header("Content-type: text/plain");
echo "<?xml version=\"1.0\"?>\r\n"
?>
<catalog>
<title><?php echo $category; ?> by New York Women Composers</title>
<cataloging_info>
<abstract>Compositions by the members of New York Women Composers</abstract>
<keyword>music publishing</keyword>
<keyword>scores</keyword>
<keyword>women composers</keyword>
<keyword>New York</keyword>
</cataloging_info>
<last_updated>July 28, 1999</last_updated>
<copyright>1999 New York Women Composers</copyright>
<maintainer>
<name>Elliotte Rusty Harold</name>
<email>elharo@macfaq.com</email>
<url>http://www.macfaq.com/personal.html</url>
</maintainer>
<?php
$connected = mysql_connect("luna.oit.unc.edu", "clerk", "mypassword");
$result = mysql("NYWC", "select WorkName, ComposerLastName, ComposerFirstName, ComposerMiddleName,
PublisherName, CompositionDate, CompositionLength, CompositionDescription,
NumPiccolos, NumFlutes, NumOboes, NumEnglishHorns, NumClarinets,
NumBbClarinets, NumBassClarinets, NumBassoons,
NumContrabassoons, NumFrenchHorns, NumTrumpets, NumTrombones,
NumBassTrombones, NumTubas, NumTimpanis, NumPercussions,
NumTriangles, NumCymbalss, NumCelestas, NumXylophones,
NumMarimbas, NumVibraphones, NumHarps, NumGuitars, NumPianos,
NumHarpsichords, NumColuraturaSopranos, NumMezzoSopranos,
NumAltos, NumTenors, NumBaritones, NumBasss, NumViolins,
NumViolas, NumCellos, NumDoubleBasss, NumChoruss, OtherInstruments
from works WHERE Category = '$category'");
for ($i = 0; $i < mysql_numrows ($result); $i++) {
echo "\r\n <composition>\r\n";
$fields = mysql_fetch_row($result);
$last = "\r\n <first_name>$fields[1]</first_name>";
$first = "\r\n <last_name>$fields[2]</last_name>";
if ($fields[3] != "") $middle = "\r\n <middle_name>$fields[3]</middle_name>";
else $middle = "";
echo " <composer>$first $middle $last\r\n </composer>";
$seconds = $fields[6];
if ($seconds > 0) $length="<length>$seconds</length>";
else $length = "";
$abbreviations = array("pic", "fl", "ob", "Ehn", "cl", "Bb cl", "bs cl", "bn", "cbn",
"hn", "tpt", "tbn", "b tbn", "tu", "timp", "perc", "tri", "cym",
"cel", "xyl", "mar", "vib", "hp", "guit", "pn", "hpschd", "sop",
"mez", "al", "ten", "bar", "bs", "vln", "vla", "vc", "cb",
"ch");
$instruments = "";
for ($j = 8; $j <= 44; $j++) {
if ($fields[$j] > 1) {
$index = $j-8;
$instruments = $instruments . ", $fields[$j] $abbreviations[$index]";
}
else if ($fields[$j] == 1) {
$index = $j-8;
$instruments = $instruments . ", $abbreviations[$index]";
}
}
if (strlen($fields[45]) >= 1) {
$instruments = $instruments . ", $fields[45]";
}
$instruments = trim($instruments);
if ($instruments != "") {
$instruments = substr($instruments, 2);
$instruments = "\r\n <instruments>$instruments</instruments>";
}
$publisher = $fields[4];
if ($publisher != "") $publisher = "\r\n <publisher>$publisher</publisher>";
$description = $fields[7];
if ($description != "") $description = "\r\n <description>$description</description>";
$date = substr($fields[5], 0, 4);
if ($date == "0000") $date = "";
else $date = "\r\n <date><year>$date</year></date>";
$name = ereg_replace("&", "&", $fields[0]);
$description = ereg_replace("&", "&", $description);
$instruments = ereg_replace("&", "&", $instruments);
echo "\r\n <name>$name</name> $date $length $instruments $description $publisher\r\n </composition>\r\n";
}
mysql_close() ;
?>
</catalog>
View in Web Browser