Jump to content


Autotrim article body text

  • Please log in to reply
1 reply to this topic

#1 haydndup

  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationJohannesburg, South Africa

Posted 27 April 2006 - 10:49 AM

I have a news section on the website that I am currently designing. I was hoping someone could give some advice on writing a function that will take text and trim it down to about 20 words... Basically giving a summary on each news item. I would then have a link to view the full article.

Thanks in advance.
[!--coloro:#660000--][span style="color:#660000"][!--/coloro--]The Gene Pool Could Use A Little Chlorine[!--colorc--][/span][!--/colorc--]

#2 KrisNz

  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 27 April 2006 - 11:41 AM

Heres how I did it, I dont know how efficent it is but hey, it works.
$string = "here is a string that has a few words in it and is fairly long and boring and needs to be trimmed
down so that it doesnt keep going and going and going and going";
$a = explode(" ",$string,21);
$output = implode(" ",$a);
echo $output;

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users