<?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) {
    $text = preg_split('#[?!.]#u', $text, -1, PREG_SPLIT_NO_EMPTY);
    foreach($text as $input){
    	$input = trim($input);
    	echo "$input\n";
    	$input = preg_split('//u', $input, -1, PREG_SPLIT_NO_EMPTY);
    	$input[0] = mb_strtoupper($input[0]);
    	$input = implode("", $input);echo "$input\n";
    }
    echo $text[0];
    $text = implode(".",$text);
    return $text;
}

/* исправляет текст */
function fixText($text){
	$text = makeFirstLetterUppercase($text);
	$reg = '#([А-Я]\\.)#u';
	$text = preg_replace($reg, "$1 ", $text);
	return $text;
}

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