Background:
I have written a code below to accept a message from Html form.The form element has a input field with name="message".
I am trying my hand on OOPs way of doing the things, and I know there is a lots of room for improvement to what i have written below. Can you improve it for me with a explainations please.
P.S. the code below is functional,it does the work but may be in nasty way...
<?php
$var = $_POST['message'];
class Message {
public $file;
public $entry;
private function cleanIt($text) {
return strip_tags($text);
}
public function getFile($fileName) {
$this->file = $fileName;
}
public function getEntry($entry) {
$this->entry = $this->cleanIt($entry);
}
public function writeInto() {
$handler = fopen($this->file,'a+');
fwrite($handler,($this->entry."\n"));
fclose($handler);
}
public function readFrom() {
$arr = file($this->file);
$text;
foreach($arr as $val)
$text .= $val.'<br />';
echo $text;
}
}
$Message = new Message;
$Message -> getFile('entries.txt');
$Message -> getEntry($var);
$Message -> writeInto();
$Message -> readFrom();
?>
Thanks