Check and cut the strings by length in PHP

function striptext($message, $position)
{
if (strlen($message) > $position) // Check if string length is exceeded
{
$post = substr($message,$position,1);
if ($post !=” “) // If last character is not space
{
while($post !=” “) // Check next character one by one
{
$i=1;
$position=$position+$i;
$post = substr($message,$position,1);
}
}
$post = substr($message,0,$position);
$text = $post . ‘…’; // Add dots
} else {
$text = $message . ‘…’; // Or do nothing
}
return($text);
}
Usage: [...]