Re: 'Intelligently' truncate string?

From: Date: Mon, 18 Oct 2004 19:37:01 +0000
Subject: Re: 'Intelligently' truncate string?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-199761@lists.php.net to get a copy of this message
On Mon, 2004-10-18 at 14:35, Murray @ PlanetThoughtful wrote: > Hi All, > I'm working on a page where I'm attempting to display article titles in a > relatively narrow area. To save from ugly wrap-arounds in the links, I've > decided to truncate the article title string at 20 chars. This works well > except where the truncate occasionally falls in the middle of a HTML entity > reference (eg   or © etc). after you do your usual truncation just add the following: $truncated = ereg_replace( '&[[:alpha:]]*$', '', $truncated ); You may need to replace alpha with alnum since I can't remember if there are any entities with digits :) Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#199761) next »