Following function shortens a string to 350 characters, considering word boundaries. Chopping off in the middle of words is avoided.
Code: Select all
function strShortenText($strText, $length=350) {
if (strlen($strText) > $length) {
$pattern = '/^(.{0,'.$length.'}\\b).*$/s';
$strText = preg_replace($pattern, "$1...", $strText);
}
return $strText;
}How to? Eventually directly with a PHP function?
Thanks,
visionmaster