Hi,
I'm working on my news posting script and was wondering how I could possibly limit the characters of the $body value to a certain number and after that number have a "...[more]" link where the user could click to be taken to a page with the full result. My problem is I can' t seem to get the limit function to work at all. If someone could please help me out and look at my code to see what I could put in there that'd be great! Here's a snipplet...
// Build query to fetch news from database
$query = "SELECT * FROM news WHERE hotnews = 'Yes' ORDER BY posted DESC";
// Execute query
$result = @mysql_query($query);
// If query was okay AND we have at least 1 updates item...
if ($result && @mysql_num_rows($result) > 0)
{
// Initialise variable to hold updates items
$hbnewsText = "";
// For each updates item returned from query...
while($row = mysql_fetch_array($result))
{
// Format date in 'mm/dd/yy' format
$posted = strftime("%m.%d.%y", $row['posted']);
if ($row['img'] != null)
{
$img = '<img border="10" src="cms/uploads/breaking_news/thumb.php?file=photos/' . $row['img'] . '&nocache=1&size=120" hspace="0" vspace="0"
align="left" style="border-color:#efefef;">';
}
$hbnewsText .= '<table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-bottom: 10px;">';
$hbnewsText .= '<tr bgcolor="#ff0000" height="14">';
$hbnewsText .= '<td align="left" valign="middle" width="76">';
$hbnewsText .= '<img src="files/images/breaking_news/hot_news_title.jpg" border="0" width="68" height="14" style="padding-right: 6px;padding-left:
2px;">';
$hbnewsText .= '</td>';
$hbnewsText .= '<td align="left" valign="middle" width="100%">';
$hbnewsText .= '<font color="#efefef">(' . $posted . ')</font> <font color="#ffffff">' . $row['title'] . '</font>';
$hbnewsText .= '</td>';
$hbnewsText .= '</tr>';
$hbnewsText .= '<tr>';
$hbnewsText .= '<td align="left" valign="top" colspan="2">';
$hbnewsText .= $img;
$hbnewsText .= stripslashes($row['body']);
$hbnewsText .= '</td>';
$hbnewsText .= '</tr>';
$hbnewsText .= '<tr height="1" bgcolor="#ff0000">';
$hbnewsText .= '<td colspan="2">';
$hbnewsText .= '</td>';
$hbnewsText .= '</tr>';
$hbnewsText .= '</table>';
// EMAIL PARSER
$pattern = '/\[(email|EMAIL)=(.*?)\](.*?)\[\/(EMAIL|email)\]/';
$replace = '<a href="mailto:\\2">\\3</a>';
$hbnewsText = preg_replace($pattern, $replace, $hbnewsText);
// URL PARSER
$pattern = '/\[(url|URL)=(.*?)\](.*?)\[\/(URL|url)\]/';
$replace = '<a href="\\2" target="_blank">\\3</a>';
$hbnewsText = preg_replace($pattern, $replace, $hbnewsText);
// NEWLINE PARSER
$hbnewsText = ereg_replace("\r\n", "<br>", $hbnewsText);
}
// Output news item
print ($hbnewsText);
}
Thanks in advance!