Relatively new to PHP, so I hope someone can help me with this. Its giving me a headache!
I'm creating a small CMS for a website that I administer. At present I'm trying to create a class that manipulates news stories.
I have the following code....
<?php
Class news
{
var $link;
var $text;
var $title;
function news($link, $text, $title)
{
$this->link = $link;
$this->text = $text;
$this->title = $title;
}
function show_short()
{
$output = '
<div id="news-item">
<p lang="ga">
<span id="news-date">'.$this->title.'::</span>
'.$this->text.'
<a href="'.$this->link.'"><ul id="news-more"><li>Read More</li></ul></a>
</p>
</div><!--news-item-->';
return $output;
}
}
//Set up some dummy data...
$news_array = array();
for ($i = 1; $i <= 5; $i++)
{
$news_array[] = new news('#','Ocus adfeta.','29.06.07');
}
//Check its there!!!
echo "<BR>Full Array<BR>";
print_r($news_array);
//Get output...
foreach ($news_array as $news_item)
{
$news_stories = $news_stories.$news_item->show_short;
}
echo $news_stories;
?>
I would expect this to give the dummy data formatted by PRINT_R and then the $news_stories variable output, created by the HTML inside the news class. The first part works fine, so I'm content that the data is within the array, however the 'show_short' doesn't seem to work.
Can anybody give me some advice?
Many thanks in advance.
Jamie