Код:
function trimBody($theText, $lmt=100, $s_chr="@@@", $s_cnt=1) {
$pos = 0;
$trimmed = FALSE;
for ($i = 1; $i <= $s_cnt; $i++) {
if ($tmp = strpos($theText, $s_chr, $pos)) {
$pos = $tmp;
$trimmed = TRUE;
} else {
$pos = strlen($theText);
$trimmed = FALSE;
break;
}
}
$theText = substr($theText, 0, $pos);
if (strlen($theText) > $lmt) {
$theText = substr($theText, 0, $lmt);
$theText = substr($theText, 0, strrpos($theText,' '));
$trimmed = TRUE;
}
if ($trimmed) $theText .= '...';
return $theText;
}
Код:
<?php require('conn.php');
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to db' . mysql_error());
mysql_select_db(SQL_DB, $conn);
$sql = ("SELECT advert_date, advert_message FROM advert_post ORDER BY advert_date DESC LIMIT 10");
$result = mysql_query($sql)
or die(mysql_error());
while ($rows = mysql_fetch_array($result)) {
extract($rows);
echo "<tr>\n";
echo "<td class=\"td1\">";
echo "<div align=\"left\">" . $advert_date . "</div></td>\n";
echo "<td class=\"td1\">";
echo "<div align=\"left\">" . $advert_message . "</div></td>\n";
echo "</tr>\n";
}
?>