Forum Moderators: coopster

Message Too Old, No Replies

Printing an excerpt

         

asantos

9:57 pm on Aug 21, 2006 (gmt 0)

10+ Year Member



Hi, i have a small problem by printing an excerpt. Supose i have this:

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla bibendum. Integer accumsan. Donec rhoncus imperdiet pede. Praesent euismod porta tortor."

I need to print an excerpt that only shows the first 20 characters. But i dont want the function to cut a word, for example:
"Lorem ipsum dolor si"

That should be:
"Lorem ipsum dolor sit"

Any ideas? Thanks.

asantos

10:57 pm on Aug 21, 2006 (gmt 0)

10+ Year Member



nevermind, heres the solution

<?
$text = strip_tags($rs->fields['data'],'<p>,<br>,<a>,<strong>,<em>,<blockquote>,<ol>,<ul>,<li>,<span>');
$min = 220;
$extra = strpos(substr($text,$min),' ');
$max = $min + $extra;
echo substr($text,0,$max);
if($min!=$max) echo '...';
?>