Chopping text

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Chopping text

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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().
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Post Reply