PHP Code:
if ($bbcode == strtoupper($bbcode)) {
$bbarr = explode ('.', $bbcode);
$bbcode = "";
foreach ($bbarr as $bbsentence) {
if (trim($bbsentence) != "") {
$bbcode .= ucfirst(strtolower(ltrim($bbsentence))) . ".";
}
}
}
It only happened if the last letter of the text was a period.
I guess that's what you get for not testing your code properly

That should do it.