<?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 = $s . $text;
return $text;
}
/* исправляет текст */
function fixText($text) {
$regexp1 = "/([.!?])/ui";
$sentences = preg_split($regexp1, $text, 0, PREG_SPLIT_NO_EMPTY
|PREG_SPLIT_DELIM_CAPTURE);
foreach ($sentences as $key => &$value) {
$value = makeFirstLetterUppercase($value);
if ($key % 2 == 1) {
$value .= " ";
}
}
$newtext = implode("", $sentences);
$regexp2 = "/([,;])/ui";
$phrases = preg_split($regexp2, $newtext, 0, PREG_SPLIT_NO_EMPTY
|PREG_SPLIT_DELIM_CAPTURE);
foreach ($phrases as $key => &$value) {
if ($key % 2 == 1) {
$value .= " ";
}
}
return $result;
}
$result = fixText($text);
echo "{$result}\n";
PD9waHAKIAplcnJvcl9yZXBvcnRpbmcoLTEpOwptYl9pbnRlcm5hbF9lbmNvZGluZygndXRmLTgnKTsKIAokdGV4dCA9ICLQvdGDINGH0YLQvi4gICAgICDQvdC1INGB0LzQvtGC0YDQtdC7INC10YnQtSBibGFjayBtZXNhLtGPINGB0L7QsdC40YDQsNC70YHRjyDRgdC60LDRh9Cw0YLRjCAgLNC90L4g0LLRgdC1INC60LDQui3RgtC+INC90LXQutC+0LPQtNCwINCx0YvQu9C+LiI7Ci8vINCU0LvRjyDRgtC10YHRgtC+0LIKIC8vJHRleHQgPSAiJ3Jvc2VzIGFyZSByZWQsYW5kIHZpb2xldHMgYXJlIGJsdWUud2hhdGV2ZXIgeW91IGRvIGknbGwga2VlcCBpdCBmb3IgeW91LiciOwovLyAkdGV4dCA9ICfQv9GA0LjQstC10YIu0LXRgdGC0YwgMiDRhNGD0L3QutGG0LjQuCxwcmVnX3NwbGl0INC4IGV4cGxvZGUgLNC90LUg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