
<?php
error_reporting(-1);
header("Content-Type: text/plain; charset=utf-8");
mb_internal_encoding('utf-8');

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

function fix($text) 
{
//$array=preg_split('/\./u',$text);
$array=explode(".",$text);
foreach($array as &$value)
{
    $firstChar=mb_substr($value,0,1,'utf-8');
    $firstChar=mb_strtoupper($firstChar,'utf-8');
    $value=substr_replace($value,$firstChar,0,1);
    $value=preg_replace('/ *\, */u',', ',$value);
    //$value=mb_ereg_replace('/ *\, */u',', ',$value);
    //$value=str_replace(",", ", ", $value);
}

return implode(". ",$array);
}

echo fix($text),"\n";
echo fix($text1),"\n";
echo fix($text2),"\n";
?>