<?php
 
error_reporting(-1);
mb_internal_encoding('utf-8');
 
//$text = "ну что.      не смотрел еще black mesa. я собирался скачать  ,но все как-то некогда было.";
// Для тестов
$text = 'roses are red   ,  nd violets are blue    .     whatever you do i\'ll keep it for you.';
//$text = 'привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.';
 
/* Делает первую букву в строке заглавной */
function makeFirstLetterUppercase($text) {
  $output = array ();
 //$space = explode('.', $text);
 $text = preg_replace('/\.[\s]*(\w)/u', '. $1', $text);
 $text = preg_replace('/(\w)\.(\w)/u', '$1. $2', $text);
 $text = preg_replace('/(\w)\,(\w)/u', '$1, $2', $text);
 $text = preg_replace('/(\w)[\s?]*\,[\s?]*(\w)/u', '$1, $2', $text);
 $text = explode('.', $text);

  foreach ($text as $key => $value) {
 	$word=trim($value);
 	$firstLetter = mb_substr($word, 0, 1);
 	$firstLetter = mb_strtoupper($firstLetter);
 	$word = mb_substr($word, 1);
 	$word = $firstLetter.$word;
 	array_push($output, $word);

  }
  return $output;
}

/* исправляет текст */
function fixText($text) {
  $output = makeFirstLetterUppercase($text);
  $text = implode(". ", $output);
  return $text;

}
 
$result = fixText($text);
echo "{$result}\n";