<html>
<head>
<link href="style/main.css" rel="stylesheet" text="text/css">
</head>
<body>
<?php
//Paging & Sort. Not the most optimized solution, but it works :)
//Written by Sindre Mathisen
class xmlreader {
var $navn; // <navn></navn>
var $email; // <email></email>
var $beskjed; // <melding></melding>
function xmlreader ($aa) {
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readDatabase($filename) {
// read the xml "database"
$data = implode("",file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($parser,$data,$values,$tags);
xml_parser_free($parser); // loop through the structures
foreach ($tags as $key=>$val) {
//hvis det er en start node
if ($key == "melding") {
$molranges = $val;
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parse(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
} function parse($mvalues) {
for ($i=0; $i < count($mvalues); $i++)
$mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
return new xmlreader($mol);
} $db = readDatabase("mynews.xml");
echo "Utskrift over mynews.xml:\n";
//print_r($db);
$mange = count ($db);
//*******************************************************
//Her kan vi gjore snacksene ting med structen :)
sort($db);
//vi faar en sortert tabell :)
//det finnes et utall andre maater aa sortere denne tabellen paa
//søking i tabellen
while ($i = each($db)) {
if ($i["value"]->navn == "Sindre Mathisen") {
echo "Sindre Mathisen fant jeg på plass:" ,
$i["key"];
}
}
//Dere skjonner cluet tenker jeg :)
//*******************************************************
for($kk=0; $kk < $mange; $kk++)
{
echo "<table border=1 width=300><tr><td><strong>Navn:</strong></td><td>";
echo $db[$kk]->navn;
echo "</td></tr><tr><td><strong>Email:</strong></td><td>";
echo $db[$kk]->email;
echo "</td></tr><tr><td><strong>Beskjed</strong></td><td>";
echo $db[$kk]->beskjed;
echo "</td></tr></table><br><br>";
}
?>
</p>
</body>
</html>