<?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) {
	$chars = preg_split('//u', $text, -1, PREG_SPLIT_NO_EMPTY);
	$chars[0] = mb_strtoupper($chars[0]);
	$sentence = implode('', $chars);
	return $sentence;
}

function fixText($text) {
	$matches = array();
	$matches = splitText($text);
	$result = '';
    foreach($matches as $match) {
	    $match = preg_replace('/(^\s+)/u', '', $match);
	    $match = makeFirstLetterUppercase($match);
	    $result .= $match;
    }
    //$result = preg_replace('/([,.;:!?])/ui')
}

function splitText($text) {
	$matches = preg_split("/(?<=[?!.])/u", $text, -1, PREG_SPLIT_NO_EMPTY);
	return $matches;
}


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

