Как да сложа ... към статия

shaxaaa

Registered
Код:
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";
}
?>
Ето тука трябва някакси да го вмъкна за да го прави и да съкращава на 100 символ да си сложи 3 точки и линк към цялата статия. Ако някой може да помогне ще съм му много благодарен
 
shaxaaa каза:
Код:
<?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);
[color=red]  $advert_message=substr($text,0 , 100);[/color]
  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 . "[color=red] ... [/color]</div></td>\n";
  echo "</tr>\n";
}
?>
 
Така ми излизат само 3 точки и нищо друго. Ако ги махна или ги сложа преди кавичките не ми изкарва пък нищо
 
моя е грешката
<?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);
$advert_message=substr($advert_message,0 , 100);
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";
}
?>
 

Горе