I'm trying to take a string and cut it off at a certain point (basically to provide a preview of the selected text) but there may be images or similar content inside (using BBCode for this) and I was wondering if there was a simple way to do this in PHP.
Example:
$content = "blah blah blah such and such [img]imagehere[/img] blah blah";
$preview=unknownfunction($content); //cuts off at approx. 40 chars
//do not want this:
$preview="blah blah blah such and such [img]image";//this is bad because half of image is gone
//want this:
$preview="blah blah blah such and such [img]imagehere[/img]"; //this is good because even though it reached 40 chars, it let it finish the image.
Is there a simple way to do this? Or at the very least, I could remove all tags from the preview element, but I'd still like this function to not cut off any words.