You are here: Re: [PHP] Newbie Question: breaking a substr() string on a space « PHP « IT news, forums, messages
Re: [PHP] Newbie Question: breaking a substr() string on a space

Posted by John Nichel on 10/03/82 11:10

Jackson Linux wrote:
> Hi, everyone, I apologise if this posts twice; I'm having issues with my
> outgoing email server.
>
> I'm making '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?
>
> Thanks in advance,
> Jack
>

You can do something like this...

function subEndWord ( $string, $start, $max ) {
$string = substr ( $string, $start, $max );
$string = preg_replace ( "/\s\w+$/", "", $string );
return $string;
}

Untested, but should work. Tinker with the RegEx to perfect it.

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@kegworks.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация