<?php
	error_reporting(-1);
	mb_internal_encoding('utf-8');
	$test = array();
 	$test[] = "ну что.      не смотрел еще black mesa.я собирался скачать  ,но все как-то некогда было.";
	$test[] = "roses are red,and violets are blue.whatever you do i'll keep it for you.";
	$test[] = "привет.есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница.";
	 
	function makeFirstLetterUppercase($text) {
	    return mb_strtoupper(mb_substr($text, 0, 1)).mb_substr($text, 1);
	}
	
	function addSpacingInPunctuation($text) {
		return preg_replace('/\\s*([,:;]+)\\s*/u', '$1 ', $text);
	}
	
	/* исправляет текст */
	function fixText($text) {
		$matches = preg_split("/(?<=[!?.])\\s*(?=\\w\\d)/u", $text);
		$matches = array_map('makeFirstLetterUppercase', $matches);
		$matches = array_map('addSpacingInPunctuation', $matches);
		return implode(' ', $matches);
	 
	}
	foreach($test as $text){
		$result = fixText($text);
		echo "{$result}\n";
	}
?>