Make function that limits text not show last punctuation mark
<p>I have this function that limits text, lets say to 50 chars like above:</p>

<pre><code>$bio = limit_text($bio, 50);

function limit_text($text, $length){ // Limit Text
    if(strlen($text) &gt; $length) {
        $text = substr($text, 0, strpos($text, ' ', $length));
    }
    return $text;
}
</code></pre>

<p>This should echo something like:</p>

<p><em>Hello, this is a text limited to 50 chars and it's a great ...</em></p>

<p><strong>The problem is that the function shows the last punctuation mark which does not look professional. Like in this example:</strong></p>

<p><em>Hello, this is a text limited to 50 chars and it has a comma at the end, ...</em></p>

<p>Is there any way to make the function not show the last punctuation mark?</p>

<p>Thank you!</p>
