I have this function that limits text, lets say to 50 chars like above:
$bio = limit_text($bio, 50);
function limit_text($text, $length){ // Limit Text
if(strlen($text) > $length) {
$text = substr($text, 0, strpos($text, ' ', $length));
}
return $text;
}
This should echo something like:
Hello, this is a text limited to 50 chars and it’s a great …
The problem is that the function shows the last punctuation mark which does not look professional. Like in this example:
Hello, this is a text limited to 50 chars and it has a comma at the end, …
Is there any way to make the function not show the last punctuation mark?
Thank you!
1 Answer