<?php
//This script adds a guestbook-entry in the XML-file. Modify it to your needs
//Written by Sindre Mathisen
if (empty($navn)) {
//We do not want blank entries
exit(0);
}
$my_xml_file = "mynews.xml";
// Reading in the xml file as a string
$fd=fopen("$my_xml_file", "r") or die("Can't open file.");
$fstr = fread($fd, filesize($my_xml_file)) or die("Can't read file; check permissions.");
fclose($fd);
// Format response sets.
$XML_name = str_replace("\'", "", $XML_name);
$XML_name = str_replace(" ", "_", $XML_name);
//Add new guestbook data
$separator = "</gjestebok>";
$divide = explode($separator, $fstr);
$glue =
"\t<melding>
\t<navn>$navn</navn>
\t<email>$mail</email>
\t<beskjed>$beskjed</beskjed>
\t</melding>
</gjestebok>
";
$newxml = implode($glue, $divide);
//Write to file
$fd = fopen($my_xml_file, "w") or die ("Can't open file for writing; check file permissions");
$writestr = fwrite($fd, $newxml);
?>