<?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) {
return $text;
}
/* Корректирует пробелы вокруг символа (,) */
function correctSpacesAroundChar($text, $char) {
$parts_of_sentence = explode($char, $text);
$text = '';
foreach ($parts_of_sentence as $part) {
$text .= $part . ', ';
}
return $text;
}
/* исправляет текст */
function fixText($text){
$sentences = preg_split("/([^!\?\.?]+[!\?\.?]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE
| PREG_SPLIT_NO_EMPTY
); foreach ($sentences as $id => $sentence ) {
$sentences[$id] = makeFirstLetterUppercase($sentence);
$sentences[$id] = correctSpacesAroundChar($sentences[$id], ',');
}
return $text;
}
$result = fixText($text);
echo "{$result}\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Cm1iX2ludGVybmFsX2VuY29kaW5nKCd1dGYtOCcpOwoKLy8kdGV4dCA9ICIgICDQvdGDINGH0YLQvi4gICAgICDQvdC1INGB0LzQvtGC0YDQtdC7INC10YnQtSBibGFjayBtZXNhLtGPINGB0L7QsdC40YDQsNC70YHRjyDRgdC60LDRh9Cw0YLRjCAgLNC90L4g0LLRgdC1INC60LDQui3RgtC+INC90LXQutC+0LPQtNCwINCx0YvQu9C+LiI7Ci8vINCU0LvRjyDRgtC10YHRgtC+0LIKIC8vJHRleHQgPSAicm9zZXMgYXJlIHJlZCxhbmQgdmlvbGV0cyBhcmUgYmx1ZS53aGF0ZXZlciB5b3UgZG8gaSdsbCBrZWVwIGl0IGZvciB5b3UuIjsKICR0ZXh0ID0gJ9C/0YDQuNCy0LXRgi7QtdGB0YLRjCAyINGE0YPQvdC60YbQuNC4LHByZWdfc3BsaXQg0LggZXhwbG9kZSAs0L3QtSDQv9C+0L3QuNC80LDRjizQsiDRh9C10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