<?php
$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_replace('/^.(.*)/u', $firstLetter.'$1', $text);
return $text;
}
/* исправляет текст */
function fixText($text) {
$sentences = preg_split('/[.?!]+/', $text, -1, PREG_SPLIT_NO_EMPTY
); $punctuationMarks = array(); $newText = "";
foreach($sentences as $i => $sentence){
$sentence = trim($sentence); $sentence = makeFirstLetterUppercase($sentence);
$sentence = preg_replace('/\s*([,:;])(\S+)/u', '$1 $2', $sentence); $newText .= $sentence.$punctuationMarks[0][$i]." ";
}
return $newText;
}
$result = fixText($text);
echo "{$result}";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKIAokdGV4dCA9ICLQvdGDINGH0YLQvj8hICAgICAg0L3QtSDRgdC80L7RgtGA0LXQuyDQtdGJ0LUgYmxhY2sgbWVzYS7RjyDRgdC+0LHQuNGA0LDQu9GB0Y8g0YHQutCw0YfQsNGC0YwgICzQvdC+INCy0YHQtSDQutCw0Lot0YLQviDQvdC10LrQvtCz0LTQsCDQsdGL0LvQvi4iOwovLyDQlNC70Y8g0YLQtdGB0YLQvtCyCi8vJHRleHQgPSAicm9zZXMgYXJlIHJlZCxhbmQgdmlvbGV0cyBhcmUgYmx1ZS53aGF0ZXZlciB5b3UgZG8gaSdsbCBrZWVwIGl0IGZvciB5b3UuIjsKLy8kdGV4dCA9ICfQv9GA0LjQstC10YIu0LXRgdGC0YwgMiDRhNGD0L3QutGG0LjQuCxwcmVnX3NwbGl0INC4IGV4cGxvZGUgLNC90LUg0L/QvtC90LjQvNCw0Y4s0LIg0YfQtdC8INC80LXQttC00YMg0L3QuNC80Lgg0YDQsNC30L3QuNG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