<?php
class guestbook {
        private 
$file_name;
        private 
$xml;
        
        function 
__construct($filename) {
            
$this->file_name $filename;
            
$this->xml simplexml_load_file($this->file_name);
        }
               
        public function 
printFile() { 
            
            
/* Skriv ut tittel og rating for alle filmer  */
            
foreach ($this->xml->hilsen as $hilsen) {
                echo 
"<h2>" utf8_decode($hilsen->tittel) . "</h2>";
                echo 
"<blockquote>" utf8_decode($hilsen->tekst) . "</blockquote>";
                echo 
"Bes&oslash;k min <a href='" utf8_decode($hilsen->web) . "'>hjemmeside</a><br />";
                echo 
utf8_decode($hilsen->dato) . "<br />";  
                echo 
"<hr>";
            }
        }

        public function 
addToFilehilsen $post) {  
            
            
$nytt_innlegg $this->xml->addChild('hilsen');
            
$nytt_innlegg->addChild("tittel",utf8_encode($post->visTittel()));
            
$nytt_innlegg->addChild("web",utf8_encode($post->visUrl()));
            
$nytt_innlegg->addChild("tekst",utf8_encode($post->visTekst()));
            
$nytt_innlegg->addChild("dato",utf8_encode($post->visDato()));
                       
            
$status $this->xml->asXml($this->file_name);
            if(!
$status) print ("Error during save of XML document");

        }

    }
?>