Re: [PHP] 'Intelligently' truncate string?
You could also try a combination of html_entity_decode to change all entities back, then truncate it, then use html_entities to get back to the encoded string. Hope this helps Cherrs Chris Robert Cummings wrote: 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 nbsp; or copy; 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] 'Intelligently' truncate string?
-Original Message- 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. Check out the user contributed notes in manual for substr. There's an example there of how to keep words intact and it sounds like it might apply to your situation. Ed Lazor, President http://RPGStore.com Up to 50% off. Over 20,000 items in stock -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] 'Intelligently' truncate string?
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 nbsp; or copy; 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
Re: [PHP] 'Intelligently' truncate string?
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 nbsp; or copy; 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. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php