<?php

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

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

/* Делает первую букву в строке заглавной */
function makeFirstLetterUppercase($text) {
    $clauses = preg_split('/([!?.])/', $text, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    $text = '';
    foreach ($clauses as $key => $clause) {
        $clause = ltrim($clause);
        $firstLetter = mb_strtoupper(mb_substr($clause, 0, 1));
        $clause = $firstLetter . mb_substr($clause, 1);
        $text .= $clause;
    }
    return $text;
}

/* исправляет текст */
function fixText($text) {
    $text = makeFirstLetterUppercase($text);
    $text = preg_replace('/ *([!?.,:;]) */', '$1 ', $text);
    return $text;
}

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