fork download
  1. <?php
  2.  
  3.  
  4. //$text = "ну что. не смотрел еще black mesa.я собирался скачать ,но все как-то некогда было.";
  5. // Для тестов
  6. // $text = "roses are red,and violets are blue.whatever you do i'll keep it for you.";
  7. $text = 'привет!есть 2 функции,preg_split и explode ,не понимаю,в чем между ними разница?';
  8.  
  9. /* Делает первую букву в строке заглавной */
  10. function makeFirstLetterUppercase($text) {
  11. $clauses = preg_split('/([!?.])/', $text, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  12. $text = '';
  13. foreach ($clauses as $key => $clause) {
  14. $clause = ltrim($clause);
  15. $firstLetter = mb_strtoupper(mb_substr($clause, 0, 1));
  16. $clause = $firstLetter . mb_substr($clause, 1);
  17. $text .= $clause;
  18. }
  19. return $text;
  20. }
  21.  
  22. /* исправляет текст */
  23. function fixText($text) {
  24. $text = makeFirstLetterUppercase($text);
  25. $text = preg_replace('/ *([!?.,:;]) */', '$1 ', $text);
  26. return $text;
  27. }
  28.  
  29. $result = fixText($text);
  30. echo "{$result}\n";
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Привет! Есть 2 функции, preg_split и explode, не понимаю, в чем между ними разница?