Testing 1 2 3

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 21, 2012   (RSS)

By Dave - December 10, 2012 - edited: December 21, 2012

Testing

1
2
3

Dave Edis - Senior Developer
interactivetools.com

By Dave - December 21, 2012

Replying back with a test code block:

 // usage: echo sforum_getPostSnippet($message));
function sforum_getPostSnippet($html) {
$snippet = $html;
$snippet = preg_replace("/<br\s*\/?>\n?/", "\n", $snippet); // replace breaks with nexlines
$snippet = strip_tags($snippet); // strip tags
$maxLength = 255;
$currentLength = strlen($snippet);
if (preg_match("/^(.{0,$maxLength})(\s|$)/s", $snippet, $matches)) { $snippet = $matches[1]; } // chop at first whitespace break before 140 chars
else { $snippet = mb_substr($snippet, 0, $maxLength); } // otherwise force cut at maxlength (for content with no whitespace such as malicious or non-english)
$wasShortened = strlen($snippet) < $currentLength;

End of message

Dave Edis - Senior Developer
interactivetools.com