Forums

This topic is locked

make long text shorter

Posted 23 Oct 2010 16:29:59
1
has voted
23 Oct 2010 16:29:59 Vivian Eersels posted:
How can I make a long text from db result shorter?
some like blblblabla ... (see more)

this is my code:

<?php echo $row_Recordset1['details']; ?>

I tried already trim
<?php echo ltrim($row_Recordset1['details']); ?>
and
<?php echo chop($row_Recordset1['details']); ?>
but that doesn't fix it
webpage on www.kidsshop.be/speelgoed.php
I have dw cs3

Replies

Replied 26 Oct 2010 13:03:57
26 Oct 2010 13:03:57 Patrick Woldberg replied:
trim/chop will only remove whitespaces, you'll need substr.
<?php echo substr($row_Recordset1['details'], 0, 100); ?>

Above code will only show first 100 characters. Better is the next function:
function maxchar($str, $max) {
  if (len($str) < $max) return $str;
  $newstr = wordwrap($str, $max, "&hellip;@@", true);
  $pos = strpos($newstr, '@@');
  return substr($newstr, 0, $pos);
}

use it like:
<?php echo maxchar($row_Recordset1['details'], 100); ?>

Reply to this topic