<?php

error_reporting(-1);
mb_internal_encoding('utf-8');

$text = "ну что.      не смотрел еще black mesa.я собирался скачать  ,но все как-то некогда было.";
// Для тестов
$text1 = "roses are red,and violets are blue.whatever you do i'll keep it for you.";
$text2 = "привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.";

/* Делает первую букву в строке заглавной */
function makeFirstLetterUppercase($text) {
//	$matches = [];
	$firstLetter = "/^[а-яёa-z]/u";
	preg_match($firstLetter, $text, $match);
	$match[0] = mb_strtoupper($match[0]);
	$text = preg_replace($firstLetter, $match[0], $text, $limit = 1);
	$regexp = "/[.!?] *[а-яёa-z]/u";
	preg_match_all($regexp, $text, $matches);
	foreach($matches as $null => $replacement){
		foreach($replacement as $nothing => $replacer){
			$pattern = $replacer;
			$replacer = mb_strtoupper($replacer);
			$text = str_replace($pattern, $replacer, $text);
		}
	}
	return $text;
}
/*исправляет текст */ 
function fixText($text) {
	$mP = [
	". " => "/ *[.] */",
	"? " => "/ *[?] */",
	", " => "/ *[,] */",
	"! " => "/ *[!] */"];
	foreach($mP as $m => $p){
		$text = preg_replace($p, $m, $text);
	}
	return $text;
}
$text = makeFirstLetterUppercase($text);
$result = fixText($text);
echo "{$result}\n";
$text1 = makeFirstLetterUppercase($text1);
$result = fixText($text1);
echo "{$result}\n";
$text2 = makeFirstLetterUppercase($text2);
$result = fixText($text2);
echo "{$result}\n";