Re: Newbie Question: breaking a substr() string on a space

From: Date: Fri, 11 Mar 2005 17:36:47 +0000
Subject: Re: Newbie Question: breaking a substr() string on a space
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-210523@lists.php.net to get a copy of this message
> Hi, everyone, > > I'm 'teasers' of the first, say 200 to 250 characters of some articles. > This works great: > > $content = strip_tags($article['content']); > $striptease = substr($content, 0, 275); > > but cuts off words right in the midd ... > > I'd like to find a way to take $content, look at the first 250 > characters, then count backwards to the last space and chop it there. > > Does anyone have an ideas/scripts for this? $pos = strpos($content, ' '); $pos = $pos ? $pos : strlen($content); $teaser = substr($content, 0, $pos); -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#210523) next »