Page 1 of 1

Chopping text

Posted: Sun Dec 24, 2006 5:11 pm
by John Cartwright
Merry Christmas everyone! Isn't it fun working on Christmas eve? :evil:

Code: Select all

preg_match('#^\s*(.{'.$maxchop.',}?)\s+.*$#s', $article['body'], $match);
This will obviously chop text after a certain number of characters, without chopping in the middle of words. Now that I've moved to a WYSIWYG editor, html tags have been introduced. Anyone have any idea how to implement this so instead of now chopping in the middle of a word, to not chop until the closing tag is found.

Posted: Tue Dec 26, 2006 8:13 am
by feyd
due to the nesting nature of html tags, I'd suggest strpos() (or preg_match() to find the position) instead, then use substr().

Posted: Thu Dec 28, 2006 10:14 pm
by John Cartwright
Thanks feyd, forgot about this thread :x

Decided to go the route of adding any missing tags after chopping the text, that way I can avoid potentially long "snipplets" of posts. Hopefully have something to post tommorow.