Hi All!
Okay, I posted this one a while back but it's still giving me a headache!
Below is a class I've set up to hold a news item:
class NewsStory
{
var $NewsID;
var $Author;
var $Headline;
var $TimeStamp;
var $NewsText;
function NewsStory($NewsID = "", $newHeadline = "", $newNewsText = "", $newAuthor = "", $newTimestamp = "")
{
$this->Author = $newAuthor;
$this->Headline = $newHeadline;
$this->Timestamp = $newTimestamp;
$this->NewsText = $newNewsText;
}
}
Then I've got another class that, along with other info and proper member functions, holds an array of these beasties:
class News
{
var $Stories;
var $StoryCount;
function News()
{
$this->Stories = array();
$this->StoryCount = 0;
}
function LoadFromFile($Filename)
{
if(!file_exists($Filename))
{
return false;
}
if (!$file = fopen($Filename, "rb"))
{
return false;
}
$this = unserialize(fread($file, 1000));
fclose($file);
for ($count=0; $count < $this->StoryCount; $count++)
{
$this->Stories[$count]->NewsText = stripcslashes($this->Stories[$count]->NewsText);
$this->Stories[$count]->Headline = stripcslashes($this->Stories[$count]->Headline);
}
return true;
}
function AddStory($newHeadline, $newNewsText, $newAuthor, $newTimestamp)
{
$newNewsText = ereg_replace("\n", "<br>", $newNewsText);
$this->Stories[] = new NewsStory($this->StoryCount, $newHeadline, $newNewsText, $newAuthor, $newTimestamp);
$this->StoryCount++;
return true;
}
...lots of other member functions here...
}
Okay, all it fine on my Win32 system running Apache and PHP4 but when I u/l the script to my server (Linux running PHP3) I get all sorts of parse errors.
I slowly went through the code commenting out the lines that gave me errors and I noticed a trend. All the erronous lines were similar to the following:
$this->Stories[$count]->NewsText = stripcslashes($this->Stories[$count]->NewsText);
By all like this I mean that they were all lines that took an element of the Stories array and referenced an attribute within that news object instance.
So here's my question. Can I do this in PHP3? If not is there a way of getting around it? Please help...my site is without a proper news engine at the moment!
Thanks greatly in advance!
Steve Webster