<?php

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

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

function makeFirstLetterUppercase($text) {
	$parts = preg_split('/(?<=[.!?])/u', $text, 0, PREG_SPLIT_NO_EMPTY);
		foreach($parts as $key => $sentence) {
			$sentence = trim($sentence);
			$otherPart = mb_substr($sentence, 1);
			$firstLetter = mb_strtoupper(mb_substr($sentence, 0, 1));
			$sentence = $firstLetter . $otherPart;
			$text = str_replace($parts[$key], $sentence, $text);
		}
	return $text;
}

function fixText($text) {
	$regexpTooManySpaces = '/\\s*([.,!?;])\\s*/';
	$result = preg_replace($regexpTooManySpaces, '$1 ', $text);
	return $result;
}

$text = makeFirstLetterUppercase($text);
$text = fixText($text);
echo $text;