On Tue, 19 Oct 2004 04:35:21 +1000, Murray @ PlanetThoughtful <[EMAIL PROTECTED]> wrote: > 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). > > I'm wondering if anyone else on the list has worked out a way of > intelligently truncating a string to take these kinds of occurrences into > account? I don't mind, in these situations if the truncation takes place > before or after the entity, since when displayed it will only equate to one > character more or less.
You can use wordwrap() to do intelligent line breaks, then you can truncate the new string based on a line break. You can also explode() the string into an array then rebuild a new string with only so many elements of the array. -- Greg Donald Zend Certified Engineer http://gdconsultants.com/ http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php